1 : /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 : * vim: set ts=4 sw=4 et tw=99 ft=cpp:
3 : *
4 : * ***** BEGIN LICENSE BLOCK *****
5 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 : *
7 : * The contents of this file are subject to the Mozilla Public License Version
8 : * 1.1 (the "License"); you may not use this file except in compliance with
9 : * the License. You may obtain a copy of the License at
10 : * http://www.mozilla.org/MPL/
11 : *
12 : * Software distributed under the License is distributed on an "AS IS" basis,
13 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 : * for the specific language governing rights and limitations under the
15 : * License.
16 : *
17 : * The Original Code is SpiderMonkey JavaScript engine.
18 : *
19 : * The Initial Developer of the Original Code is
20 : * Mozilla Corporation.
21 : * Portions created by the Initial Developer are Copyright (C) 2011
22 : * the Initial Developer. All Rights Reserved.
23 : *
24 : * Contributor(s):
25 : * Chris Leary <cdleary@mozilla.com>
26 : *
27 : * Alternatively, the contents of this file may be used under the terms of
28 : * either the GNU General Public License Version 2 or later (the "GPL"), or
29 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 : * in which case the provisions of the GPL or the LGPL are applicable instead
31 : * of those above. If you wish to allow use of your version of this file only
32 : * under the terms of either the GPL or the LGPL, and not to allow others to
33 : * use your version of this file under the terms of the MPL, indicate your
34 : * decision by deleting the provisions above and replace them with the notice
35 : * and other provisions required by the GPL or the LGPL. If you do not delete
36 : * the provisions above, a recipient may use your version of this file under
37 : * the terms of any one of the MPL, the GPL or the LGPL.
38 : *
39 : * ***** END LICENSE BLOCK ***** */
40 :
41 : #ifndef ParseMapPool_inl_h__
42 : #define ParseMapPool_inl_h__
43 :
44 : #include "jscntxt.h"
45 :
46 : #include "frontend/ParseNode.h" /* Need sizeof(js::Definition). */
47 :
48 : #include "ParseMaps.h"
49 :
50 : namespace js {
51 :
52 : template <>
53 : inline AtomDefnMap *
54 1112912 : ParseMapPool::acquire<AtomDefnMap>()
55 : {
56 1112912 : return reinterpret_cast<AtomDefnMap *>(allocate());
57 : }
58 :
59 : template <>
60 : inline AtomIndexMap *
61 1203787 : ParseMapPool::acquire<AtomIndexMap>()
62 : {
63 1203787 : return reinterpret_cast<AtomIndexMap *>(allocate());
64 : }
65 :
66 : template <>
67 : inline AtomDOHMap *
68 1112912 : ParseMapPool::acquire<AtomDOHMap>()
69 : {
70 1112912 : return reinterpret_cast<AtomDOHMap *>(allocate());
71 : }
72 :
73 : inline void *
74 3429611 : ParseMapPool::allocate()
75 : {
76 3429611 : if (recyclable.empty())
77 231051 : return allocateFresh();
78 :
79 3198560 : void *map = recyclable.popCopy();
80 3198560 : asAtomMap(map)->clear();
81 3198560 : return map;
82 : }
83 :
84 : inline Definition *
85 6760024 : AtomDecls::lookupFirst(JSAtom *atom)
86 : {
87 6760024 : JS_ASSERT(map);
88 6760024 : AtomDOHPtr p = map->lookup(atom);
89 6760024 : if (!p)
90 5628474 : return NULL;
91 1131550 : if (p.value().isHeader()) {
92 : /* Just return the head defn. */
93 24901 : return p.value().header()->defn;
94 : }
95 1106649 : return p.value().defn();
96 : }
97 :
98 : inline MultiDeclRange
99 14936325 : AtomDecls::lookupMulti(JSAtom *atom)
100 : {
101 14936325 : JS_ASSERT(map);
102 14936325 : AtomDOHPtr p = map->lookup(atom);
103 14936325 : if (!p)
104 9276295 : return MultiDeclRange((Definition *) NULL);
105 :
106 5660030 : DefnOrHeader &doh = p.value();
107 5660030 : if (doh.isHeader())
108 898542 : return MultiDeclRange(doh.header());
109 4761488 : return MultiDeclRange(doh.defn());
110 : }
111 :
112 : inline bool
113 2556323 : AtomDecls::addUnique(JSAtom *atom, Definition *defn)
114 : {
115 2556323 : JS_ASSERT(map);
116 2556323 : AtomDOHAddPtr p = map->lookupForAdd(atom);
117 2556323 : if (p) {
118 18 : JS_ASSERT(!p.value().isHeader());
119 18 : p.value() = DefnOrHeader(defn);
120 18 : return true;
121 : }
122 2556305 : return map->add(p, atom, DefnOrHeader(defn));
123 : }
124 :
125 : template <class Map>
126 : inline bool
127 : AtomThingMapPtr<Map>::ensureMap(JSContext *cx)
128 : {
129 2437169 : if (map_)
130 120470 : return true;
131 2316699 : map_ = cx->parseMapPool().acquire<Map>();
132 2316699 : return !!map_;
133 : }
134 :
135 : template <class Map>
136 : inline void
137 : AtomThingMapPtr<Map>::releaseMap(JSContext *cx)
138 : {
139 6221395 : if (!map_)
140 3905282 : return;
141 2316113 : cx->parseMapPool().release(map_);
142 2316113 : map_ = NULL;
143 : }
144 :
145 : inline bool
146 1112912 : AtomDecls::init()
147 : {
148 1112912 : map = cx->parseMapPool().acquire<AtomDOHMap>();
149 1112912 : return map;
150 : }
151 :
152 : inline
153 2089395 : AtomDecls::~AtomDecls()
154 : {
155 2089395 : if (map)
156 1112912 : cx->parseMapPool().release(map);
157 2089395 : }
158 :
159 : } /* namespace js */
160 :
161 : #endif
|