Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: src/objects.h

Issue 6525: Calculate string hash during flattening. (Closed)
Patch Set: Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap.cc ('k') | src/objects.cc » ('j') | src/objects.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1797 matching lines...) Expand 10 before | Expand all | Expand 10 after
1808 // because only the symbol itself (the key) needs to be stored. 1808 // because only the symbol itself (the key) needs to be stored.
1809 class SymbolTable: public HashTable<0, 1> { 1809 class SymbolTable: public HashTable<0, 1> {
1810 public: 1810 public:
1811 // Find symbol in the symbol table. If it is not there yet, it is 1811 // Find symbol in the symbol table. If it is not there yet, it is
1812 // added. The return value is the symbol table which might have 1812 // added. The return value is the symbol table which might have
1813 // been enlarged. If the return value is not a failure, the symbol 1813 // been enlarged. If the return value is not a failure, the symbol
1814 // pointer *s is set to the symbol found. 1814 // pointer *s is set to the symbol found.
1815 Object* LookupSymbol(Vector<const char> str, Object** s); 1815 Object* LookupSymbol(Vector<const char> str, Object** s);
1816 Object* LookupString(String* key, Object** s); 1816 Object* LookupString(String* key, Object** s);
1817 1817
1818 // Looks up a symbol that is equal to the given string and returns
1819 // true if it is found, assigning the symbol to the given output
1820 // parameter.
1821 bool LookupSymbolIfExists(String* str, String** symbol);
1822
1818 // Casting. 1823 // Casting.
1819 static inline SymbolTable* cast(Object* obj); 1824 static inline SymbolTable* cast(Object* obj);
1820 1825
1821 private: 1826 private:
1822 Object* LookupKey(HashTableKey* key, Object** s); 1827 Object* LookupKey(HashTableKey* key, Object** s);
1823 1828
1824 DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolTable); 1829 DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolTable);
1825 }; 1830 };
1826 1831
1827 1832
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
2832 static const int kTypeOffset = JSObject::kHeaderSize; 2837 static const int kTypeOffset = JSObject::kHeaderSize;
2833 static const int kDataOffset = kTypeOffset + kIntSize; 2838 static const int kDataOffset = kTypeOffset + kIntSize;
2834 static const int kSize = kDataOffset + kIntSize; 2839 static const int kSize = kDataOffset + kIntSize;
2835 }; 2840 };
2836 2841
2837 2842
2838 enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS}; 2843 enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS};
2839 enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL}; 2844 enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL};
2840 2845
2841 2846
2847 class StringHasher {
2848 public:
2849 inline StringHasher(int length);
2850
2851 // Returns true if the hash of this string can be computed without
2852 // looking at the contents.
2853 inline bool has_trivial_hash();
2854
2855 // Add a character to the hash and update the array index calculation.
2856 inline void AddCharacter(uc32 c);
2857
2858 // Adds a character to the hash but does not update the array index
2859 // calculation. This can only be called when it has been verified
2860 // that the input is not an array index.
2861 inline void AddCharacterNoIndex(uc32 c);
2862
2863 // Returns the value to store in the hash field of a string with
2864 // the given length and contents.
2865 uint32_t GetHashField();
2866
2867 // Returns true if the characters seen so far make up a legal array
2868 // index.
2869 bool is_array_index() { return is_array_index_; }
2870
2871 bool is_valid() { return is_valid_; }
2872
2873 void invalidate() { is_valid_ = false; }
2874
2875 private:
2876
2877 uint32_t array_index() {
2878 ASSERT(is_array_index());
2879 return array_index_;
2880 }
2881
2882 inline uint32_t GetHash();
2883
2884 int length_;
2885 uint32_t raw_running_hash_;
2886 uint32_t array_index_;
2887 bool is_array_index_;
2888 bool is_first_char_;
2889 bool is_valid_;
2890 };
2891
2892
2842 // The String abstract class captures JavaScript string values: 2893 // The String abstract class captures JavaScript string values:
2843 // 2894 //
2844 // Ecma-262: 2895 // Ecma-262:
2845 // 4.3.16 String Value 2896 // 4.3.16 String Value
2846 // A string value is a member of the type String and is a finite 2897 // A string value is a member of the type String and is a finite
2847 // ordered sequence of zero or more 16-bit unsigned integer values. 2898 // ordered sequence of zero or more 16-bit unsigned integer values.
2848 // 2899 //
2849 // All string values have a length field. 2900 // All string values have a length field.
2850 class String: public HeapObject { 2901 class String: public HeapObject {
2851 public: 2902 public:
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
2973 inline bool IsFlat(); 3024 inline bool IsFlat();
2974 3025
2975 // Layout description. 3026 // Layout description.
2976 static const int kLengthOffset = HeapObject::kHeaderSize; 3027 static const int kLengthOffset = HeapObject::kHeaderSize;
2977 static const int kSize = kLengthOffset + kIntSize; 3028 static const int kSize = kLengthOffset + kIntSize;
2978 3029
2979 // Limits on sizes of different types of strings. 3030 // Limits on sizes of different types of strings.
2980 static const int kMaxShortStringSize = 255; 3031 static const int kMaxShortStringSize = 255;
2981 static const int kMaxMediumStringSize = 65535; 3032 static const int kMaxMediumStringSize = 65535;
2982 3033
3034 static const int kMaxArrayIndexSize = 10;
3035
2983 // Max ascii char code. 3036 // Max ascii char code.
2984 static const int kMaxAsciiCharCode = 127; 3037 static const int kMaxAsciiCharCode = 127;
2985 3038
2986 // Mask constant for checking if a string has a computed hash code 3039 // Mask constant for checking if a string has a computed hash code
2987 // and if it is an array index. The least significant bit indicates 3040 // and if it is an array index. The least significant bit indicates
2988 // whether a hash code has been computed. If the hash code has been 3041 // whether a hash code has been computed. If the hash code has been
2989 // computed the 2nd bit tells whether the string can be used as an 3042 // computed the 2nd bit tells whether the string can be used as an
2990 // array index. 3043 // array index.
2991 static const int kHashComputedMask = 1; 3044 static const int kHashComputedMask = 1;
2992 static const int kIsArrayIndexMask = 1 << 1; 3045 static const int kIsArrayIndexMask = 1 << 1;
(...skipping 24 matching lines...) Expand all
3017 unibrow::byte* util_buffer, 3070 unibrow::byte* util_buffer,
3018 unsigned capacity, 3071 unsigned capacity,
3019 unsigned* remaining, 3072 unsigned* remaining,
3020 unsigned* offset); 3073 unsigned* offset);
3021 3074
3022 // Helper function for flattening strings. 3075 // Helper function for flattening strings.
3023 static void Flatten(String* source, 3076 static void Flatten(String* source,
3024 String* sink, 3077 String* sink,
3025 int from, 3078 int from,
3026 int to, 3079 int to,
3027 int sink_offset); 3080 int sink_offset,
3081 StringHasher* hasher);
3028 3082
3029 protected: 3083 protected:
3030 class ReadBlockBuffer { 3084 class ReadBlockBuffer {
3031 public: 3085 public:
3032 ReadBlockBuffer(unibrow::byte* util_buffer_, 3086 ReadBlockBuffer(unibrow::byte* util_buffer_,
3033 unsigned cursor_, 3087 unsigned cursor_,
3034 unsigned capacity_, 3088 unsigned capacity_,
3035 unsigned remaining_) : 3089 unsigned remaining_) :
3036 util_buffer(util_buffer_), 3090 util_buffer(util_buffer_),
3037 cursor(cursor_), 3091 cursor(cursor_),
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
3919 } else { 3973 } else {
3920 value &= ~(1 << bit_position); 3974 value &= ~(1 << bit_position);
3921 } 3975 }
3922 return value; 3976 return value;
3923 } 3977 }
3924 }; 3978 };
3925 3979
3926 } } // namespace v8::internal 3980 } } // namespace v8::internal
3927 3981
3928 #endif // V8_OBJECTS_H_ 3982 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « src/heap.cc ('k') | src/objects.cc » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698