gfx/angle/src/compiler/Common.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 (c) 2002-2010 The ANGLE Project Authors. All rights reserved.
     3 // Use of this source code is governed by a BSD-style license that can be
     4 // found in the LICENSE file.
     5 //
     7 #ifndef _COMMON_INCLUDED_
     8 #define _COMMON_INCLUDED_
    10 #include <map>
    11 #include <sstream>
    12 #include <string>
    13 #include <vector>
    15 #include "compiler/PoolAlloc.h"
    17 struct TSourceLoc {
    18     int first_file;
    19     int first_line;
    20     int last_file;
    21     int last_line;
    22 };
    24 //
    25 // Put POOL_ALLOCATOR_NEW_DELETE in base classes to make them use this scheme.
    26 //
    27 #define POOL_ALLOCATOR_NEW_DELETE()                                                  \
    28     void* operator new(size_t s) { return GetGlobalPoolAllocator()->allocate(s); }   \
    29     void* operator new(size_t, void *_Where) { return (_Where); }                    \
    30     void operator delete(void*) { }                                                  \
    31     void operator delete(void *, void *) { }                                         \
    32     void* operator new[](size_t s) { return GetGlobalPoolAllocator()->allocate(s); } \
    33     void* operator new[](size_t, void *_Where) { return (_Where); }                  \
    34     void operator delete[](void*) { }                                                \
    35     void operator delete[](void *, void *) { }
    37 //
    38 // Pool version of string.
    39 //
    40 typedef pool_allocator<char> TStringAllocator;
    41 typedef std::basic_string <char, std::char_traits<char>, TStringAllocator> TString;
    42 typedef std::basic_ostringstream<char, std::char_traits<char>, TStringAllocator> TStringStream;
    43 inline TString* NewPoolTString(const char* s)
    44 {
    45 	void* memory = GetGlobalPoolAllocator()->allocate(sizeof(TString));
    46 	return new(memory) TString(s);
    47 }
    49 //
    50 // Persistent string memory.  Should only be used for strings that survive
    51 // across compiles.
    52 //
    53 #define TPersistString std::string
    54 #define TPersistStringStream std::ostringstream
    56 //
    57 // Pool allocator versions of vectors, lists, and maps
    58 //
    59 template <class T> class TVector : public std::vector<T, pool_allocator<T> > {
    60 public:
    61     typedef typename std::vector<T, pool_allocator<T> >::size_type size_type;
    62     TVector() : std::vector<T, pool_allocator<T> >() {}
    63     TVector(const pool_allocator<T>& a) : std::vector<T, pool_allocator<T> >(a) {}
    64     TVector(size_type i): std::vector<T, pool_allocator<T> >(i) {}
    65 };
    67 template <class K, class D, class CMP = std::less<K> > 
    68 class TMap : public std::map<K, D, CMP, pool_allocator<std::pair<const K, D> > > {
    69 public:
    70     typedef pool_allocator<std::pair<const K, D> > tAllocator;
    72     TMap() : std::map<K, D, CMP, tAllocator>() {}
    73     // use correct two-stage name lookup supported in gcc 3.4 and above
    74     TMap(const tAllocator& a) : std::map<K, D, CMP, tAllocator>(std::map<K, D, CMP, tAllocator>::key_compare(), a) {}
    75 };
    77 #endif // _COMMON_INCLUDED_

mercurial