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

Side by Side Diff: src/objects.h

Issue 9083001: Use a random seed for the string hash algorithm. Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 8 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « src/isolate.cc ('k') | src/objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 6099 matching lines...) Expand 10 before | Expand all | Expand 10 after
6110 DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCacheHashTable); 6110 DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCacheHashTable);
6111 }; 6111 };
6112 6112
6113 6113
6114 enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS}; 6114 enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS};
6115 enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL}; 6115 enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL};
6116 6116
6117 6117
6118 class StringHasher { 6118 class StringHasher {
6119 public: 6119 public:
6120 explicit inline StringHasher(int length); 6120 explicit inline StringHasher(int length, uint32_t seed);
6121 6121
6122 // Returns true if the hash of this string can be computed without 6122 // Returns true if the hash of this string can be computed without
6123 // looking at the contents. 6123 // looking at the contents.
6124 inline bool has_trivial_hash(); 6124 inline bool has_trivial_hash();
6125 6125
6126 // Add a character to the hash and update the array index calculation. 6126 // Add a character to the hash and update the array index calculation.
6127 inline void AddCharacter(uc32 c); 6127 inline void AddCharacter(uc32 c);
6128 6128
6129 // Adds a character to the hash but does not update the array index 6129 // Adds a character to the hash but does not update the array index
6130 // calculation. This can only be called when it has been verified 6130 // calculation. This can only be called when it has been verified
(...skipping 30 matching lines...) Expand all
6161 uint32_t array_index_; 6161 uint32_t array_index_;
6162 bool is_array_index_; 6162 bool is_array_index_;
6163 bool is_first_char_; 6163 bool is_first_char_;
6164 bool is_valid_; 6164 bool is_valid_;
6165 friend class TwoCharHashTableKey; 6165 friend class TwoCharHashTableKey;
6166 }; 6166 };
6167 6167
6168 6168
6169 // Calculates string hash. 6169 // Calculates string hash.
6170 template <typename schar> 6170 template <typename schar>
6171 inline uint32_t HashSequentialString(const schar* chars, int length); 6171 inline uint32_t HashSequentialString(const schar* chars,
6172 int length,
6173 uint32_t seed);
6172 6174
6173 6175
6174 // The characteristics of a string are stored in its map. Retrieving these 6176 // The characteristics of a string are stored in its map. Retrieving these
6175 // few bits of information is moderately expensive, involving two memory 6177 // few bits of information is moderately expensive, involving two memory
6176 // loads where the second is dependent on the first. To improve efficiency 6178 // loads where the second is dependent on the first. To improve efficiency
6177 // the shape of the string is given its own class so that it can be retrieved 6179 // the shape of the string is given its own class so that it can be retrieved
6178 // once and used for several string operations. A StringShape is small enough 6180 // once and used for several string operations. A StringShape is small enough
6179 // to be passed by value and is immutable, but be aware that flattening a 6181 // to be passed by value and is immutable, but be aware that flattening a
6180 // string can potentially alter its shape. Also be aware that a GC caused by 6182 // string can potentially alter its shape. Also be aware that a GC caused by
6181 // something else can alter the shape of a string due to ConsString 6183 // something else can alter the shape of a string due to ConsString
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
6384 SmartArrayPointer<uc16> ToWideCString( 6386 SmartArrayPointer<uc16> ToWideCString(
6385 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); 6387 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL);
6386 6388
6387 // Tells whether the hash code has been computed. 6389 // Tells whether the hash code has been computed.
6388 inline bool HasHashCode(); 6390 inline bool HasHashCode();
6389 6391
6390 // Returns a hash value used for the property table 6392 // Returns a hash value used for the property table
6391 inline uint32_t Hash(); 6393 inline uint32_t Hash();
6392 6394
6393 static uint32_t ComputeHashField(unibrow::CharacterStream* buffer, 6395 static uint32_t ComputeHashField(unibrow::CharacterStream* buffer,
6394 int length); 6396 int length,
6397 uint32_t seed);
6395 6398
6396 static bool ComputeArrayIndex(unibrow::CharacterStream* buffer, 6399 static bool ComputeArrayIndex(unibrow::CharacterStream* buffer,
6397 uint32_t* index, 6400 uint32_t* index,
6398 int length); 6401 int length);
6399 6402
6400 // Externalization. 6403 // Externalization.
6401 bool MakeExternal(v8::String::ExternalStringResource* resource); 6404 bool MakeExternal(v8::String::ExternalStringResource* resource);
6402 bool MakeExternal(v8::String::ExternalAsciiStringResource* resource); 6405 bool MakeExternal(v8::String::ExternalAsciiStringResource* resource);
6403 6406
6404 // Conversion. 6407 // Conversion.
(...skipping 1603 matching lines...) Expand 10 before | Expand all | Expand 10 after
8008 } else { 8011 } else {
8009 value &= ~(1 << bit_position); 8012 value &= ~(1 << bit_position);
8010 } 8013 }
8011 return value; 8014 return value;
8012 } 8015 }
8013 }; 8016 };
8014 8017
8015 } } // namespace v8::internal 8018 } } // namespace v8::internal
8016 8019
8017 #endif // V8_OBJECTS_H_ 8020 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698