LCOV - code coverage report
Current view: directory - js/src/ds - BitArray.h (source / functions) Found Hit Coverage
Test: app.info Lines: 20 15 75.0 %
Date: 2012-06-02 Functions: 5 4 80.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                 :  *   Terrence Cole <terrence@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 BitArray_h__
      42                 : #define BitArray_h__
      43                 : 
      44                 : #include "jstypes.h" 
      45                 : 
      46                 : #include "js/TemplateLib.h" 
      47                 : 
      48                 : namespace js {
      49                 : 
      50                 : template <size_t nbits>
      51                 : class BitArray {
      52                 :   private:
      53                 :     uintptr_t map[nbits / JS_BITS_PER_WORD + (nbits % JS_BITS_PER_WORD == 0 ? 0 : 1)];
      54                 : 
      55                 :   public:
      56           43620 :     void clear(bool value) {
      57           43620 :         if (value)
      58               0 :             memset(map, 0xFF, sizeof(map));
      59                 :         else
      60           43620 :             memset(map, 0, sizeof(map));
      61           43620 :     }
      62                 : 
      63        11624237 :     inline bool get(size_t offset) const {
      64                 :         uintptr_t index, mask;
      65        11624237 :         getMarkWordAndMask(offset, &index, &mask);
      66        11624237 :         return map[index] & mask;
      67                 :     }
      68                 : 
      69            4140 :     inline void set(size_t offset) {
      70                 :         uintptr_t index, mask;
      71            4140 :         getMarkWordAndMask(offset, &index, &mask);
      72            4140 :         map[index] |= mask;
      73            4140 :     }
      74                 : 
      75               0 :     inline void unset(size_t offset) {
      76                 :         uintptr_t index, mask;
      77               0 :         getMarkWordAndMask(offset, &index, &mask);
      78               0 :         map[index] &= ~mask;
      79               0 :     }
      80                 : 
      81                 :   private:
      82        11628377 :     inline void getMarkWordAndMask(size_t offset,
      83                 :                                    uintptr_t *indexp, uintptr_t *maskp) const {
      84        11628377 :         *indexp = offset >> tl::FloorLog2<JS_BITS_PER_WORD>::result;
      85        11628377 :         *maskp = uintptr_t(1) << (offset & (JS_BITS_PER_WORD - 1));
      86        11628377 :     }
      87                 : };
      88                 : 
      89                 : } /* namespace js */
      90                 : 
      91                 : #endif

Generated by: LCOV version 1.7