gfx/skia/trunk/include/device/xps/SkConstexprMath.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright 2011 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #ifndef SkConstexprMath_DEFINED
michael@0 9 #define SkConstexprMath_DEFINED
michael@0 10
michael@0 11 #include "SkTypes.h"
michael@0 12 #include <limits.h>
michael@0 13
michael@0 14 template <uintmax_t N, uintmax_t B>
michael@0 15 struct SK_LOG {
michael@0 16 //! Compile-time constant ceiling(logB(N)).
michael@0 17 static const uintmax_t value = 1 + SK_LOG<N/B, B>::value;
michael@0 18 };
michael@0 19 template <uintmax_t B>
michael@0 20 struct SK_LOG<1, B> {
michael@0 21 static const uintmax_t value = 0;
michael@0 22 };
michael@0 23 template <uintmax_t B>
michael@0 24 struct SK_LOG<0, B> {
michael@0 25 static const uintmax_t value = 0;
michael@0 26 };
michael@0 27
michael@0 28 template<uintmax_t N>
michael@0 29 struct SK_2N1 {
michael@0 30 //! Compile-time constant (2^N)-1.
michael@0 31 static const uintmax_t value = (SK_2N1<N-1>::value << 1) + 1;
michael@0 32 };
michael@0 33 template<>
michael@0 34 struct SK_2N1<1> {
michael@0 35 static const uintmax_t value = 1;
michael@0 36 };
michael@0 37
michael@0 38 /** Compile-time constant number of base n digits in type t
michael@0 39 if the bits of type t are considered as unsigned base two.
michael@0 40 */
michael@0 41 #define SK_BASE_N_DIGITS_IN(n, t) (\
michael@0 42 SK_LOG<SK_2N1<(sizeof(t) * CHAR_BIT)>::value, n>::value\
michael@0 43 )
michael@0 44 /** Compile-time constant number of base 10 digits in type t
michael@0 45 if the bits of type t are considered as unsigned base two.
michael@0 46 */
michael@0 47 #define SK_DIGITS_IN(t) SK_BASE_N_DIGITS_IN(10, (t))
michael@0 48
michael@0 49 // Compile-time constant maximum value of two unsigned values.
michael@0 50 template <uintmax_t a, uintmax_t b> struct SkTUMax {
michael@0 51 static const uintmax_t value = (b < a) ? a : b;
michael@0 52 };
michael@0 53
michael@0 54 #endif

mercurial