js/src/jshashutil.h

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

     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 {
    14 /*
    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 collection between the call to
    17  * lookupForAdd() and relookupOrAdd().
    18  */
    19 template <class T>
    20 struct DependentAddPtr
    21 {
    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
    31         {}
    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);
    41     }
    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;
    60 };
    62 } // namespace js
    64 #endif

mercurial