js/src/jit/FixedList.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 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim: set ts=8 sts=4 et sw=4 tw=99:
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef jit_FixedList_h
michael@0 8 #define jit_FixedList_h
michael@0 9
michael@0 10 #include <stddef.h>
michael@0 11
michael@0 12 #include "jit/Ion.h"
michael@0 13 #include "jit/IonAllocPolicy.h"
michael@0 14
michael@0 15 namespace js {
michael@0 16 namespace jit {
michael@0 17
michael@0 18 // List of a fixed length, but the length is unknown until runtime.
michael@0 19 template <typename T>
michael@0 20 class FixedList
michael@0 21 {
michael@0 22 T *list_;
michael@0 23 size_t length_;
michael@0 24
michael@0 25 private:
michael@0 26 FixedList(const FixedList&); // no copy definition.
michael@0 27 void operator= (const FixedList*); // no assignment definition.
michael@0 28
michael@0 29 public:
michael@0 30 FixedList()
michael@0 31 : list_(nullptr), length_(0)
michael@0 32 { }
michael@0 33
michael@0 34 // Dynamic memory allocation requires the ability to report failure.
michael@0 35 bool init(TempAllocator &alloc, size_t length) {
michael@0 36 length_ = length;
michael@0 37 if (length == 0)
michael@0 38 return true;
michael@0 39
michael@0 40 if (length & mozilla::tl::MulOverflowMask<sizeof(T)>::value)
michael@0 41 return false;
michael@0 42 list_ = (T *)alloc.allocate(length * sizeof(T));
michael@0 43 return list_ != nullptr;
michael@0 44 }
michael@0 45
michael@0 46 size_t length() const {
michael@0 47 return length_;
michael@0 48 }
michael@0 49
michael@0 50 void shrink(size_t num) {
michael@0 51 JS_ASSERT(num < length_);
michael@0 52 length_ -= num;
michael@0 53 }
michael@0 54
michael@0 55 bool growBy(TempAllocator &alloc, size_t num) {
michael@0 56 size_t newlength = length_ + num;
michael@0 57 if (newlength < length_)
michael@0 58 return false;
michael@0 59 if (newlength & mozilla::tl::MulOverflowMask<sizeof(T)>::value)
michael@0 60 return false;
michael@0 61 T *list = (T *)alloc.allocate((length_ + num) * sizeof(T));
michael@0 62 if (!list)
michael@0 63 return false;
michael@0 64
michael@0 65 for (size_t i = 0; i < length_; i++)
michael@0 66 list[i] = list_[i];
michael@0 67
michael@0 68 length_ += num;
michael@0 69 list_ = list;
michael@0 70 return true;
michael@0 71 }
michael@0 72
michael@0 73 T &operator[](size_t index) {
michael@0 74 JS_ASSERT(index < length_);
michael@0 75 return list_[index];
michael@0 76 }
michael@0 77 const T &operator [](size_t index) const {
michael@0 78 JS_ASSERT(index < length_);
michael@0 79 return list_[index];
michael@0 80 }
michael@0 81 };
michael@0 82
michael@0 83 } // namespace jit
michael@0 84 } // namespace js
michael@0 85
michael@0 86 #endif /* jit_FixedList_h */

mercurial