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-06-02 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         1115154 : ParseMapPool::acquire<AtomDefnMap>()
      55                 : {
      56         1115154 :     return reinterpret_cast<AtomDefnMap *>(allocate());
      57                 : }
      58                 : 
      59                 : template <>
      60                 : inline AtomIndexMap *
      61         1206130 : ParseMapPool::acquire<AtomIndexMap>()
      62                 : {
      63         1206130 :     return reinterpret_cast<AtomIndexMap *>(allocate());
      64                 : }
      65                 : 
      66                 : template <>
      67                 : inline AtomDOHMap *
      68         1115154 : ParseMapPool::acquire<AtomDOHMap>()
      69                 : {
      70         1115154 :     return reinterpret_cast<AtomDOHMap *>(allocate());
      71                 : }
      72                 : 
      73                 : inline void *
      74         3436438 : ParseMapPool::allocate()
      75                 : {
      76         3436438 :     if (recyclable.empty())
      77          231344 :         return allocateFresh();
      78                 : 
      79         3205094 :     void *map = recyclable.popCopy();
      80         3205094 :     asAtomMap(map)->clear();
      81         3205094 :     return map;
      82                 : }
      83                 : 
      84                 : inline Definition *
      85         6771614 : AtomDecls::lookupFirst(JSAtom *atom)
      86                 : {
      87         6771614 :     JS_ASSERT(map);
      88         6771614 :     AtomDOHPtr p = map->lookup(atom);
      89         6771614 :     if (!p)
      90         5637957 :         return NULL;
      91         1133657 :     if (p.value().isHeader()) {
      92                 :         /* Just return the head defn. */
      93           24907 :         return p.value().header()->defn;
      94                 :     }
      95         1108750 :     return p.value().defn();
      96                 : }
      97                 : 
      98                 : inline MultiDeclRange
      99        14964117 : AtomDecls::lookupMulti(JSAtom *atom)
     100                 : {
     101        14964117 :     JS_ASSERT(map);
     102        14964117 :     AtomDOHPtr p = map->lookup(atom);
     103        14964117 :     if (!p)
     104         9294199 :         return MultiDeclRange((Definition *) NULL);
     105                 : 
     106         5669918 :     DefnOrHeader &doh = p.value();
     107         5669918 :     if (doh.isHeader())
     108          899969 :         return MultiDeclRange(doh.header());
     109         4769949 :     return MultiDeclRange(doh.defn());
     110                 : }
     111                 : 
     112                 : inline bool
     113         2561318 : AtomDecls::addUnique(JSAtom *atom, Definition *defn)
     114                 : {
     115         2561318 :     JS_ASSERT(map);
     116         2561318 :     AtomDOHAddPtr p = map->lookupForAdd(atom);
     117         2561318 :     if (p) {
     118              18 :         JS_ASSERT(!p.value().isHeader());
     119              18 :         p.value() = DefnOrHeader(defn);
     120              18 :         return true;
     121                 :     }
     122         2561300 :     return map->add(p, atom, DefnOrHeader(defn));
     123                 : }
     124                 : 
     125                 : template <class Map>
     126                 : inline bool
     127                 : AtomThingMapPtr<Map>::ensureMap(JSContext *cx)
     128                 : {
     129         2441778 :     if (map_)
     130          120494 :         return true;
     131         2321284 :     map_ = cx->parseMapPool().acquire<Map>();
     132         2321284 :     return !!map_;
     133                 : }
     134                 : 
     135                 : template <class Map>
     136                 : inline void
     137                 : AtomThingMapPtr<Map>::releaseMap(JSContext *cx)
     138                 : {
     139         6233903 :     if (!map_)
     140         3913205 :         return;
     141         2320698 :     cx->parseMapPool().release(map_);
     142         2320698 :     map_ = NULL;
     143                 : }
     144                 : 
     145                 : inline bool
     146         1115154 : AtomDecls::init()
     147                 : {
     148         1115154 :     map = cx->parseMapPool().acquire<AtomDOHMap>();
     149         1115154 :     return map;
     150                 : }
     151                 : 
     152                 : inline
     153         2093498 : AtomDecls::~AtomDecls()
     154                 : {
     155         2093498 :     if (map)
     156         1115154 :         cx->parseMapPool().release(map);
     157         2093498 : }
     158                 : 
     159                 : } /* namespace js */
     160                 : 
     161                 : #endif

Generated by: LCOV version 1.7