LCOV - code coverage report
Current view: top level - src/objects - string-table.h (source / functions) Hit Total Coverage
Test: app.info Lines: 4 4 100.0 %
Date: 2019-02-19 Functions: 1 3 33.3 %

          Line data    Source code
       1             : // Copyright 2017 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_OBJECTS_STRING_TABLE_H_
       6             : #define V8_OBJECTS_STRING_TABLE_H_
       7             : 
       8             : #include "src/objects/hash-table.h"
       9             : #include "src/roots.h"
      10             : 
      11             : // Has to be the last include (doesn't have include guards):
      12             : #include "src/objects/object-macros.h"
      13             : 
      14             : namespace v8 {
      15             : namespace internal {
      16             : 
      17     1963171 : class StringTableKey : public HashTableKey {
      18             :  public:
      19             :   explicit inline StringTableKey(uint32_t hash_field);
      20             : 
      21             :   virtual Handle<String> AsHandle(Isolate* isolate) = 0;
      22             :   uint32_t HashField() const {
      23             :     DCHECK_NE(0, hash_field_);
      24             :     return hash_field_;
      25             :   }
      26             : 
      27             :  protected:
      28             :   inline void set_hash_field(uint32_t hash_field);
      29             : 
      30             :  private:
      31             :   uint32_t hash_field_ = 0;
      32             : };
      33             : 
      34             : class StringTableShape : public BaseShape<StringTableKey*> {
      35             :  public:
      36             :   static inline bool IsMatch(Key key, Object value) {
      37   118146230 :     return key->IsMatch(value);
      38             :   }
      39             : 
      40    53168949 :   static inline uint32_t Hash(Isolate* isolate, Key key) { return key->Hash(); }
      41             : 
      42             :   static inline uint32_t HashForObject(Isolate* isolate, Object object);
      43             : 
      44             :   static inline Handle<Object> AsHandle(Isolate* isolate, Key key);
      45             : 
      46             :   static inline RootIndex GetMapRootIndex();
      47             : 
      48             :   static const int kPrefixSize = 0;
      49             :   static const int kEntrySize = 1;
      50             : };
      51             : 
      52             : class SeqOneByteString;
      53             : 
      54             : // StringTable.
      55             : //
      56             : // No special elements in the prefix and the element size is 1
      57             : // because only the string itself (the key) needs to be stored.
      58             : class StringTable : public HashTable<StringTable, StringTableShape> {
      59             :  public:
      60             :   // Find string in the string table. If it is not there yet, it is
      61             :   // added. The return value is the string found.
      62             :   V8_EXPORT_PRIVATE static Handle<String> LookupString(Isolate* isolate,
      63             :                                                        Handle<String> key);
      64             :   static Handle<String> LookupKey(Isolate* isolate, StringTableKey* key);
      65             :   static Handle<String> AddKeyNoResize(Isolate* isolate, StringTableKey* key);
      66             :   static String ForwardStringIfExists(Isolate* isolate, StringTableKey* key,
      67             :                                       String string);
      68             : 
      69             :   // Shink the StringTable if it's very empty (kMaxEmptyFactor) to avoid the
      70             :   // performance overhead of re-allocating the StringTable over and over again.
      71             :   static Handle<StringTable> CautiousShrink(Isolate* isolate,
      72             :                                             Handle<StringTable> table);
      73             : 
      74             :   // Looks up a string that is equal to the given string and returns
      75             :   // string handle if it is found, or an empty handle otherwise.
      76             :   V8_WARN_UNUSED_RESULT static MaybeHandle<String> LookupTwoCharsStringIfExists(
      77             :       Isolate* isolate, uint16_t c1, uint16_t c2);
      78             :   // {raw_string} must be a tagged String pointer.
      79             :   // Returns a tagged pointer: either an internalized string, or a Smi
      80             :   // sentinel.
      81             :   static Address LookupStringIfExists_NoAllocate(Isolate* isolate,
      82             :                                                  Address raw_string);
      83             : 
      84             :   static void EnsureCapacityForDeserialization(Isolate* isolate, int expected);
      85             : 
      86             :   DECL_CAST(StringTable)
      87             : 
      88             :   static const int kMaxEmptyFactor = 4;
      89             :   static const int kMinCapacity = 2048;
      90             :   static const int kMinShrinkCapacity = kMinCapacity;
      91             : 
      92             :  private:
      93             :   template <bool seq_one_byte>
      94             :   friend class JsonParser;
      95             : 
      96    14498386 :   OBJECT_CONSTRUCTORS(StringTable, HashTable<StringTable, StringTableShape>);
      97             : };
      98             : 
      99             : class StringSetShape : public BaseShape<String> {
     100             :  public:
     101             :   static inline bool IsMatch(String key, Object value);
     102             :   static inline uint32_t Hash(Isolate* isolate, String key);
     103             :   static inline uint32_t HashForObject(Isolate* isolate, Object object);
     104             : 
     105             :   static const int kPrefixSize = 0;
     106             :   static const int kEntrySize = 1;
     107             : };
     108             : 
     109             : class StringSet : public HashTable<StringSet, StringSetShape> {
     110             :  public:
     111             :   static Handle<StringSet> New(Isolate* isolate);
     112             :   static Handle<StringSet> Add(Isolate* isolate, Handle<StringSet> blacklist,
     113             :                                Handle<String> name);
     114             :   bool Has(Isolate* isolate, Handle<String> name);
     115             : 
     116             :   DECL_CAST(StringSet)
     117             :   OBJECT_CONSTRUCTORS(StringSet, HashTable<StringSet, StringSetShape>);
     118             : };
     119             : 
     120             : }  // namespace internal
     121             : }  // namespace v8
     122             : 
     123             : #include "src/objects/object-macros-undef.h"
     124             : 
     125             : #endif  // V8_OBJECTS_STRING_TABLE_H_

Generated by: LCOV version 1.10