LCOV - app.info - js/src/frontend/ParseMaps-inl.h

LCOV - code coverage report
| Current view: | directory - js/src/frontend - ParseMaps-inl.h (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 52 | 52 | 100.0 %
| Date: | 2012-04-07 | Functions: | 9 | 9 | 100.0 %

           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          265972 : ParseMapPool::acquire<AtomDefnMap>()
          55                 : {
          56          265972 :     return reinterpret_cast<AtomDefnMap *>(allocate());
          57                 : }
          58                 :
          59                 : template <>
          60                 : inline AtomIndexMap *
          61          272267 : ParseMapPool::acquire<AtomIndexMap>()
          62                 : {
          63          272267 :     return reinterpret_cast<AtomIndexMap *>(allocate());
          64                 : }
          65                 :
          66                 : template <>
          67                 : inline AtomDOHMap *
          68          265972 : ParseMapPool::acquire<AtomDOHMap>()
          69                 : {
          70          265972 :     return reinterpret_cast<AtomDOHMap *>(allocate());
          71                 : }
          72                 :
          73                 : inline void *
          74          804211 : ParseMapPool::allocate()
          75                 : {
          76          804211 :     if (recyclable.empty())
          77          115855 :         return allocateFresh();
          78                 :
          79          688356 :     void *map = recyclable.popCopy();
          80          688356 :     asAtomMap(map)->clear();
          81          688356 :     return map;
          82                 : }
          83                 :
          84                 : inline Definition *
          85         1223427 : AtomDecls::lookupFirst(JSAtom *atom)
          86                 : {
          87         1223427 :     JS_ASSERT(map);
          88         1223427 :     AtomDOHPtr p = map->lookup(atom);
          89         1223427 :     if (!p)
          90         1188876 :         return NULL;
          91           34551 :     if (p.value().isHeader()) {
          92                 :         /* Just return the head defn. */
          93            1180 :         return p.value().header()->defn;
          94                 :     }
          95           33371 :     return p.value().defn();
          96                 : }
          97                 :
          98                 : inline MultiDeclRange
          99         2715260 : AtomDecls::lookupMulti(JSAtom *atom)
         100                 : {
         101         2715260 :     JS_ASSERT(map);
         102         2715260 :     AtomDOHPtr p = map->lookup(atom);
         103         2715260 :     if (!p)
         104         2015077 :         return MultiDeclRange((Definition *) NULL);
         105                 :
         106          700183 :     DefnOrHeader &doh = p.value();
         107          700183 :     if (doh.isHeader())
         108           24764 :         return MultiDeclRange(doh.header());
         109          675419 :     return MultiDeclRange(doh.defn());
         110                 : }
         111                 :
         112                 : inline bool
         113          481455 : AtomDecls::addUnique(JSAtom *atom, Definition *defn)
         114                 : {
         115          481455 :     JS_ASSERT(map);
         116          962910 :     AtomDOHAddPtr p = map->lookupForAdd(atom);
         117          481455 :     if (p) {
         118              18 :         JS_ASSERT(!p.value().isHeader());
         119              18 :         p.value() = DefnOrHeader(defn);
         120              18 :         return true;
         121                 :     }
         122          481437 :     return map->add(p, atom, DefnOrHeader(defn));
         123                 : }
         124                 :
         125                 : template <class Map>
         126                 : inline bool
         127                 : AtomThingMapPtr<Map>::ensureMap(JSContext *cx)
         128                 : {
         129          549508 :     if (map_)
         130           11269 :         return true;
         131          538239 :     map_ = cx->parseMapPool().acquire<Map>();
         132          538239 :     return !!map_;
         133                 : }
         134                 :
         135                 : template <class Map>
         136                 : inline void
         137                 : AtomThingMapPtr<Map>::releaseMap(JSContext *cx)
         138                 : {
         139         1000056 :     if (!map_)
         140          462402 :         return;
         141          537654 :     cx->parseMapPool().release(map_);
         142          537654 :     map_ = NULL;
         143                 : }
         144                 :
         145                 : inline bool
         146          265972 : AtomDecls::init()
         147                 : {
         148          265972 :     map = cx->parseMapPool().acquire<AtomDOHMap>();
         149          265972 :     return map;
         150                 : }
         151                 :
         152                 : inline
         153          420122 : AtomDecls::~AtomDecls()
         154                 : {
         155          420122 :     if (map)
         156          265972 :         cx->parseMapPool().release(map);
         157          420122 : }
         158                 :
         159                 : } /* namespace js */
         160                 :
         161                 : #endif

Generated by: LCOV version 1.7