Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | #include "jit/BitSet.h" |
michael@0 | 8 | |
michael@0 | 9 | using namespace js; |
michael@0 | 10 | using namespace js::jit; |
michael@0 | 11 | |
michael@0 | 12 | BitSet * |
michael@0 | 13 | BitSet::New(TempAllocator &alloc, unsigned int numBits) |
michael@0 | 14 | { |
michael@0 | 15 | BitSet *result = new(alloc) BitSet(numBits); |
michael@0 | 16 | if (!result->init(alloc)) |
michael@0 | 17 | return nullptr; |
michael@0 | 18 | return result; |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | bool |
michael@0 | 22 | BitSet::init(TempAllocator &alloc) |
michael@0 | 23 | { |
michael@0 | 24 | size_t sizeRequired = numWords() * sizeof(*bits_); |
michael@0 | 25 | |
michael@0 | 26 | bits_ = (uint32_t *)alloc.allocate(sizeRequired); |
michael@0 | 27 | if (!bits_) |
michael@0 | 28 | return false; |
michael@0 | 29 | |
michael@0 | 30 | memset(bits_, 0, sizeRequired); |
michael@0 | 31 | |
michael@0 | 32 | return true; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | bool |
michael@0 | 36 | BitSet::empty() const |
michael@0 | 37 | { |
michael@0 | 38 | JS_ASSERT(bits_); |
michael@0 | 39 | const uint32_t *bits = bits_; |
michael@0 | 40 | for (unsigned int i = 0, e = numWords(); i < e; i++) { |
michael@0 | 41 | if (bits[i]) |
michael@0 | 42 | return false; |
michael@0 | 43 | } |
michael@0 | 44 | return true; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | void |
michael@0 | 48 | BitSet::insertAll(const BitSet *other) |
michael@0 | 49 | { |
michael@0 | 50 | JS_ASSERT(bits_); |
michael@0 | 51 | JS_ASSERT(other->numBits_ == numBits_); |
michael@0 | 52 | JS_ASSERT(other->bits_); |
michael@0 | 53 | |
michael@0 | 54 | uint32_t *bits = bits_; |
michael@0 | 55 | const uint32_t *otherBits = other->bits_; |
michael@0 | 56 | for (unsigned int i = 0, e = numWords(); i < e; i++) |
michael@0 | 57 | bits[i] |= otherBits[i]; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | void |
michael@0 | 61 | BitSet::removeAll(const BitSet *other) |
michael@0 | 62 | { |
michael@0 | 63 | JS_ASSERT(bits_); |
michael@0 | 64 | JS_ASSERT(other->numBits_ == numBits_); |
michael@0 | 65 | JS_ASSERT(other->bits_); |
michael@0 | 66 | |
michael@0 | 67 | uint32_t *bits = bits_; |
michael@0 | 68 | const uint32_t *otherBits = other->bits_; |
michael@0 | 69 | for (unsigned int i = 0, e = numWords(); i < e; i++) |
michael@0 | 70 | bits[i] &= ~otherBits[i]; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | void |
michael@0 | 74 | BitSet::intersect(const BitSet *other) |
michael@0 | 75 | { |
michael@0 | 76 | JS_ASSERT(bits_); |
michael@0 | 77 | JS_ASSERT(other->numBits_ == numBits_); |
michael@0 | 78 | JS_ASSERT(other->bits_); |
michael@0 | 79 | |
michael@0 | 80 | uint32_t *bits = bits_; |
michael@0 | 81 | const uint32_t *otherBits = other->bits_; |
michael@0 | 82 | for (unsigned int i = 0, e = numWords(); i < e; i++) |
michael@0 | 83 | bits[i] &= otherBits[i]; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | // returns true if the intersection caused the contents of the set to change. |
michael@0 | 87 | bool |
michael@0 | 88 | BitSet::fixedPointIntersect(const BitSet *other) |
michael@0 | 89 | { |
michael@0 | 90 | JS_ASSERT(bits_); |
michael@0 | 91 | JS_ASSERT(other->numBits_ == numBits_); |
michael@0 | 92 | JS_ASSERT(other->bits_); |
michael@0 | 93 | |
michael@0 | 94 | bool changed = false; |
michael@0 | 95 | |
michael@0 | 96 | uint32_t *bits = bits_; |
michael@0 | 97 | const uint32_t *otherBits = other->bits_; |
michael@0 | 98 | for (unsigned int i = 0, e = numWords(); i < e; i++) { |
michael@0 | 99 | uint32_t old = bits[i]; |
michael@0 | 100 | bits[i] &= otherBits[i]; |
michael@0 | 101 | |
michael@0 | 102 | if (!changed && old != bits[i]) |
michael@0 | 103 | changed = true; |
michael@0 | 104 | } |
michael@0 | 105 | return changed; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | void |
michael@0 | 109 | BitSet::complement() |
michael@0 | 110 | { |
michael@0 | 111 | JS_ASSERT(bits_); |
michael@0 | 112 | uint32_t *bits = bits_; |
michael@0 | 113 | for (unsigned int i = 0, e = numWords(); i < e; i++) |
michael@0 | 114 | bits[i] = ~bits[i]; |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | void |
michael@0 | 118 | BitSet::clear() |
michael@0 | 119 | { |
michael@0 | 120 | JS_ASSERT(bits_); |
michael@0 | 121 | uint32_t *bits = bits_; |
michael@0 | 122 | for (unsigned int i = 0, e = numWords(); i < e; i++) |
michael@0 | 123 | bits[i] = 0; |
michael@0 | 124 | } |