summaryrefslogtreecommitdiffstats
path: root/js/src/jspropertytree.h
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/jspropertytree.h
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jspropertytree.h')
-rw-r--r--js/src/jspropertytree.h106
1 files changed, 106 insertions, 0 deletions
diff --git a/js/src/jspropertytree.h b/js/src/jspropertytree.h
new file mode 100644
index 000000000..b2544d496
--- /dev/null
+++ b/js/src/jspropertytree.h
@@ -0,0 +1,106 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * vim: set ts=8 sts=4 et sw=4 tw=99:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef jspropertytree_h
+#define jspropertytree_h
+
+#include "jsalloc.h"
+#include "jspubtd.h"
+
+#include "js/HashTable.h"
+
+namespace js {
+
+class Shape;
+struct StackShape;
+
+struct ShapeHasher : public DefaultHasher<Shape*> {
+ typedef Shape* Key;
+ typedef StackShape Lookup;
+
+ static inline HashNumber hash(const Lookup& l);
+ static inline bool match(Key k, const Lookup& l);
+};
+
+typedef HashSet<Shape*, ShapeHasher, SystemAllocPolicy> KidsHash;
+
+class KidsPointer {
+ private:
+ enum {
+ SHAPE = 0,
+ HASH = 1,
+ TAG = 1
+ };
+
+ uintptr_t w;
+
+ public:
+ bool isNull() const { return !w; }
+ void setNull() { w = 0; }
+
+ bool isShape() const { return (w & TAG) == SHAPE && !isNull(); }
+ Shape* toShape() const {
+ MOZ_ASSERT(isShape());
+ return reinterpret_cast<Shape*>(w & ~uintptr_t(TAG));
+ }
+ void setShape(Shape* shape) {
+ MOZ_ASSERT(shape);
+ MOZ_ASSERT((reinterpret_cast<uintptr_t>(static_cast<Shape*>(shape)) & TAG) == 0);
+ w = reinterpret_cast<uintptr_t>(static_cast<Shape*>(shape)) | SHAPE;
+ }
+
+ bool isHash() const { return (w & TAG) == HASH; }
+ KidsHash* toHash() const {
+ MOZ_ASSERT(isHash());
+ return reinterpret_cast<KidsHash*>(w & ~uintptr_t(TAG));
+ }
+ void setHash(KidsHash* hash) {
+ MOZ_ASSERT(hash);
+ MOZ_ASSERT((reinterpret_cast<uintptr_t>(hash) & TAG) == 0);
+ w = reinterpret_cast<uintptr_t>(hash) | HASH;
+ }
+
+#ifdef DEBUG
+ void checkConsistency(Shape* aKid) const;
+#endif
+};
+
+class PropertyTree
+{
+ friend class ::JSFunction;
+
+#ifdef DEBUG
+ JS::Zone* zone_;
+#endif
+
+ bool insertChild(ExclusiveContext* cx, Shape* parent, Shape* child);
+
+ PropertyTree();
+
+ public:
+ /*
+ * Use a lower limit for objects that are accessed using SETELEM (o[x] = y).
+ * These objects are likely used as hashmaps and dictionary mode is more
+ * efficient in this case.
+ */
+ enum {
+ MAX_HEIGHT = 512,
+ MAX_HEIGHT_WITH_ELEMENTS_ACCESS = 128
+ };
+
+ explicit PropertyTree(JS::Zone* zone)
+#ifdef DEBUG
+ : zone_(zone)
+#endif
+ {
+ }
+
+ Shape* getChild(ExclusiveContext* cx, Shape* parent, JS::Handle<StackShape> child);
+};
+
+} /* namespace js */
+
+#endif /* jspropertytree_h */