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.

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

mercurial