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

Side by Side Diff: src/objects.cc

Issue 9155010: Minor cleanups of numeric seeded hashing patch. (Closed) 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/objects.h ('k') | src/objects-inl.h » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 6911 matching lines...) Expand 10 before | Expand all | Expand 10 after
6922 // Should only be called if hash code has not yet been computed. 6922 // Should only be called if hash code has not yet been computed.
6923 ASSERT(!HasHashCode()); 6923 ASSERT(!HasHashCode());
6924 6924
6925 const int len = length(); 6925 const int len = length();
6926 6926
6927 // Compute the hash code. 6927 // Compute the hash code.
6928 uint32_t field = 0; 6928 uint32_t field = 0;
6929 if (StringShape(this).IsSequentialAscii()) { 6929 if (StringShape(this).IsSequentialAscii()) {
6930 field = HashSequentialString(SeqAsciiString::cast(this)->GetChars(), 6930 field = HashSequentialString(SeqAsciiString::cast(this)->GetChars(),
6931 len, 6931 len,
6932 GetHeap()->StringHashSeed()); 6932 GetHeap()->HashSeed());
6933 } else if (StringShape(this).IsSequentialTwoByte()) { 6933 } else if (StringShape(this).IsSequentialTwoByte()) {
6934 field = HashSequentialString(SeqTwoByteString::cast(this)->GetChars(), 6934 field = HashSequentialString(SeqTwoByteString::cast(this)->GetChars(),
6935 len, 6935 len,
6936 GetHeap()->StringHashSeed()); 6936 GetHeap()->HashSeed());
6937 } else { 6937 } else {
6938 StringInputBuffer buffer(this); 6938 StringInputBuffer buffer(this);
6939 field = ComputeHashField(&buffer, len, GetHeap()->StringHashSeed()); 6939 field = ComputeHashField(&buffer, len, GetHeap()->HashSeed());
6940 } 6940 }
6941 6941
6942 // Store the hash code in the object. 6942 // Store the hash code in the object.
6943 set_hash_field(field); 6943 set_hash_field(field);
6944 6944
6945 // Check the hash code is there. 6945 // Check the hash code is there.
6946 ASSERT(HasHashCode()); 6946 ASSERT(HasHashCode());
6947 uint32_t result = field >> kHashShift; 6947 uint32_t result = field >> kHashShift;
6948 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. 6948 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed.
6949 return result; 6949 return result;
(...skipping 3761 matching lines...) Expand 10 before | Expand all | Expand 10 after
10711 public: 10711 public:
10712 explicit SubStringAsciiSymbolKey(Handle<SeqAsciiString> string, 10712 explicit SubStringAsciiSymbolKey(Handle<SeqAsciiString> string,
10713 int from, 10713 int from,
10714 int length, 10714 int length,
10715 uint32_t seed) 10715 uint32_t seed)
10716 : string_(string), from_(from), length_(length), seed_(seed) { } 10716 : string_(string), from_(from), length_(length), seed_(seed) { }
10717 10717
10718 uint32_t Hash() { 10718 uint32_t Hash() {
10719 ASSERT(length_ >= 0); 10719 ASSERT(length_ >= 0);
10720 ASSERT(from_ + length_ <= string_->length()); 10720 ASSERT(from_ + length_ <= string_->length());
10721 StringHasher hasher(length_, string_->GetHeap()->StringHashSeed()); 10721 StringHasher hasher(length_, string_->GetHeap()->HashSeed());
10722 10722
10723 // Very long strings have a trivial hash that doesn't inspect the 10723 // Very long strings have a trivial hash that doesn't inspect the
10724 // string contents. 10724 // string contents.
10725 if (hasher.has_trivial_hash()) { 10725 if (hasher.has_trivial_hash()) {
10726 hash_field_ = hasher.GetHashField(); 10726 hash_field_ = hasher.GetHashField();
10727 } else { 10727 } else {
10728 int i = 0; 10728 int i = 0;
10729 // Do the iterative array index computation as long as there is a 10729 // Do the iterative array index computation as long as there is a
10730 // chance this is an array index. 10730 // chance this is an array index.
10731 while (i < length_ && hasher.is_array_index()) { 10731 while (i < length_ && hasher.is_array_index()) {
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after
11629 ASSERT(StringShape(result).IsSymbol()); 11629 ASSERT(StringShape(result).IsSymbol());
11630 *symbol = result; 11630 *symbol = result;
11631 return true; 11631 return true;
11632 } 11632 }
11633 } 11633 }
11634 11634
11635 11635
11636 bool SymbolTable::LookupTwoCharsSymbolIfExists(uint32_t c1, 11636 bool SymbolTable::LookupTwoCharsSymbolIfExists(uint32_t c1,
11637 uint32_t c2, 11637 uint32_t c2,
11638 String** symbol) { 11638 String** symbol) {
11639 TwoCharHashTableKey key(c1, c2, GetHeap()->StringHashSeed()); 11639 TwoCharHashTableKey key(c1, c2, GetHeap()->HashSeed());
11640 int entry = FindEntry(&key); 11640 int entry = FindEntry(&key);
11641 if (entry == kNotFound) { 11641 if (entry == kNotFound) {
11642 return false; 11642 return false;
11643 } else { 11643 } else {
11644 String* result = String::cast(KeyAt(entry)); 11644 String* result = String::cast(KeyAt(entry));
11645 ASSERT(StringShape(result).IsSymbol()); 11645 ASSERT(StringShape(result).IsSymbol());
11646 *symbol = result; 11646 *symbol = result;
11647 return true; 11647 return true;
11648 } 11648 }
11649 } 11649 }
11650 11650
11651 11651
11652 MaybeObject* SymbolTable::LookupSymbol(Vector<const char> str, 11652 MaybeObject* SymbolTable::LookupSymbol(Vector<const char> str,
11653 Object** s) { 11653 Object** s) {
11654 Utf8SymbolKey key(str, GetHeap()->StringHashSeed()); 11654 Utf8SymbolKey key(str, GetHeap()->HashSeed());
11655 return LookupKey(&key, s); 11655 return LookupKey(&key, s);
11656 } 11656 }
11657 11657
11658 11658
11659 MaybeObject* SymbolTable::LookupAsciiSymbol(Vector<const char> str, 11659 MaybeObject* SymbolTable::LookupAsciiSymbol(Vector<const char> str,
11660 Object** s) { 11660 Object** s) {
11661 AsciiSymbolKey key(str, GetHeap()->StringHashSeed()); 11661 AsciiSymbolKey key(str, GetHeap()->HashSeed());
11662 return LookupKey(&key, s); 11662 return LookupKey(&key, s);
11663 } 11663 }
11664 11664
11665 11665
11666 MaybeObject* SymbolTable::LookupSubStringAsciiSymbol(Handle<SeqAsciiString> str, 11666 MaybeObject* SymbolTable::LookupSubStringAsciiSymbol(Handle<SeqAsciiString> str,
11667 int from, 11667 int from,
11668 int length, 11668 int length,
11669 Object** s) { 11669 Object** s) {
11670 SubStringAsciiSymbolKey key(str, from, length, GetHeap()->StringHashSeed()); 11670 SubStringAsciiSymbolKey key(str, from, length, GetHeap()->HashSeed());
11671 return LookupKey(&key, s); 11671 return LookupKey(&key, s);
11672 } 11672 }
11673 11673
11674 11674
11675 MaybeObject* SymbolTable::LookupTwoByteSymbol(Vector<const uc16> str, 11675 MaybeObject* SymbolTable::LookupTwoByteSymbol(Vector<const uc16> str,
11676 Object** s) { 11676 Object** s) {
11677 TwoByteSymbolKey key(str, GetHeap()->StringHashSeed()); 11677 TwoByteSymbolKey key(str, GetHeap()->HashSeed());
11678 return LookupKey(&key, s); 11678 return LookupKey(&key, s);
11679 } 11679 }
11680 11680
11681 MaybeObject* SymbolTable::LookupKey(HashTableKey* key, Object** s) { 11681 MaybeObject* SymbolTable::LookupKey(HashTableKey* key, Object** s) {
11682 int entry = FindEntry(key); 11682 int entry = FindEntry(key);
11683 11683
11684 // Symbol already in table. 11684 // Symbol already in table.
11685 if (entry != kNotFound) { 11685 if (entry != kNotFound) {
11686 *s = KeyAt(entry); 11686 *s = KeyAt(entry);
11687 return this; 11687 return this;
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after
12744 if (break_point_objects()->IsUndefined()) return 0; 12744 if (break_point_objects()->IsUndefined()) return 0;
12745 // Single break point. 12745 // Single break point.
12746 if (!break_point_objects()->IsFixedArray()) return 1; 12746 if (!break_point_objects()->IsFixedArray()) return 1;
12747 // Multiple break points. 12747 // Multiple break points.
12748 return FixedArray::cast(break_point_objects())->length(); 12748 return FixedArray::cast(break_point_objects())->length();
12749 } 12749 }
12750 #endif // ENABLE_DEBUGGER_SUPPORT 12750 #endif // ENABLE_DEBUGGER_SUPPORT
12751 12751
12752 12752
12753 } } // namespace v8::internal 12753 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698