1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jspropertytree.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,106 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef jspropertytree_h 1.11 +#define jspropertytree_h 1.12 + 1.13 +#include "jsalloc.h" 1.14 +#include "jspubtd.h" 1.15 + 1.16 +#include "js/HashTable.h" 1.17 + 1.18 +namespace js { 1.19 + 1.20 +class Shape; 1.21 +struct StackShape; 1.22 + 1.23 +struct ShapeHasher { 1.24 + typedef Shape *Key; 1.25 + typedef StackShape Lookup; 1.26 + 1.27 + static inline HashNumber hash(const Lookup &l); 1.28 + static inline bool match(Key k, const Lookup &l); 1.29 +}; 1.30 + 1.31 +typedef HashSet<Shape *, ShapeHasher, SystemAllocPolicy> KidsHash; 1.32 + 1.33 +class KidsPointer { 1.34 + private: 1.35 + enum { 1.36 + SHAPE = 0, 1.37 + HASH = 1, 1.38 + TAG = 1 1.39 + }; 1.40 + 1.41 + uintptr_t w; 1.42 + 1.43 + public: 1.44 + bool isNull() const { return !w; } 1.45 + void setNull() { w = 0; } 1.46 + 1.47 + bool isShape() const { return (w & TAG) == SHAPE && !isNull(); } 1.48 + Shape *toShape() const { 1.49 + JS_ASSERT(isShape()); 1.50 + return reinterpret_cast<Shape *>(w & ~uintptr_t(TAG)); 1.51 + } 1.52 + void setShape(Shape *shape) { 1.53 + JS_ASSERT(shape); 1.54 + JS_ASSERT((reinterpret_cast<uintptr_t>(static_cast<Shape *>(shape)) & TAG) == 0); 1.55 + w = reinterpret_cast<uintptr_t>(static_cast<Shape *>(shape)) | SHAPE; 1.56 + } 1.57 + 1.58 + bool isHash() const { return (w & TAG) == HASH; } 1.59 + KidsHash *toHash() const { 1.60 + JS_ASSERT(isHash()); 1.61 + return reinterpret_cast<KidsHash *>(w & ~uintptr_t(TAG)); 1.62 + } 1.63 + void setHash(KidsHash *hash) { 1.64 + JS_ASSERT(hash); 1.65 + JS_ASSERT((reinterpret_cast<uintptr_t>(hash) & TAG) == 0); 1.66 + w = reinterpret_cast<uintptr_t>(hash) | HASH; 1.67 + } 1.68 + 1.69 +#ifdef DEBUG 1.70 + void checkConsistency(Shape *aKid) const; 1.71 +#endif 1.72 +}; 1.73 + 1.74 +class PropertyTree 1.75 +{ 1.76 + friend class ::JSFunction; 1.77 + 1.78 + JSCompartment *compartment_; 1.79 + 1.80 + bool insertChild(ExclusiveContext *cx, Shape *parent, Shape *child); 1.81 + 1.82 + PropertyTree(); 1.83 + 1.84 + public: 1.85 + /* 1.86 + * Use a lower limit for objects that are accessed using SETELEM (o[x] = y). 1.87 + * These objects are likely used as hashmaps and dictionary mode is more 1.88 + * efficient in this case. 1.89 + */ 1.90 + enum { 1.91 + MAX_HEIGHT = 512, 1.92 + MAX_HEIGHT_WITH_ELEMENTS_ACCESS = 128 1.93 + }; 1.94 + 1.95 + PropertyTree(JSCompartment *comp) 1.96 + : compartment_(comp) 1.97 + { 1.98 + } 1.99 + 1.100 + JSCompartment *compartment() { return compartment_; } 1.101 + 1.102 + Shape *newShape(ExclusiveContext *cx); 1.103 + Shape *getChild(ExclusiveContext *cx, Shape *parent, StackShape &child); 1.104 + Shape *lookupChild(ThreadSafeContext *cx, Shape *parent, const StackShape &child); 1.105 +}; 1.106 + 1.107 +} /* namespace js */ 1.108 + 1.109 +#endif /* jspropertytree_h */