Bumping manifests a=b2g-bump
[gecko.git] / js / src / jshashutil.h
blobd95cbd41a9ba6c701bf87691be3f0efc3b542d69
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sts=4 et sw=4 tw=99:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef jshashutil_h
8 #define jshashutil_h
10 #include "jscntxt.h"
12 namespace js {
15 * Used to add entries to a js::HashMap or HashSet where the key depends on a GC
16 * thing that may be moved by generational or compacting GC between the call to
17 * lookupForAdd() and relookupOrAdd().
19 template <class T>
20 struct DependentAddPtr
22 typedef typename T::AddPtr AddPtr;
23 typedef typename T::Entry Entry;
25 template <class Lookup>
26 DependentAddPtr(const ExclusiveContext *cx, const T &table, const Lookup &lookup)
27 : addPtr(table.lookupForAdd(lookup))
28 #ifdef JSGC_GENERATIONAL
29 , originalGcNumber(cx->zone()->gcNumber())
30 #endif
33 template <class KeyInput, class ValueInput>
34 bool add(const ExclusiveContext *cx, T &table, const KeyInput &key, const ValueInput &value) {
35 #ifdef JSGC_GENERATIONAL
36 bool gcHappened = originalGcNumber != cx->zone()->gcNumber();
37 if (gcHappened)
38 addPtr = table.lookupForAdd(key);
39 #endif
40 return table.relookupOrAdd(addPtr, key, value);
43 typedef void (DependentAddPtr::* ConvertibleToBool)();
44 void nonNull() {}
46 bool found() const { return addPtr.found(); }
47 operator ConvertibleToBool() const { return found() ? &DependentAddPtr::nonNull : 0; }
48 const Entry &operator*() const { return *addPtr; }
49 const Entry *operator->() const { return &*addPtr; }
51 private:
52 AddPtr addPtr ;
53 #ifdef JSGC_GENERATIONAL
54 const uint64_t originalGcNumber;
55 #endif
57 DependentAddPtr() MOZ_DELETE;
58 DependentAddPtr(const DependentAddPtr&) MOZ_DELETE;
59 DependentAddPtr& operator=(const DependentAddPtr&) MOZ_DELETE;
62 } // namespace js
64 #endif