Index: src/objects.cc |
=================================================================== |
--- src/objects.cc (revision 550) |
+++ src/objects.cc (working copy) |
@@ -3890,7 +3890,7 @@ |
bool String::ComputeArrayIndex(unibrow::CharacterStream* buffer, |
uint32_t* index, |
int length) { |
- if (length == 0) return false; |
+ if (length == 0 || length > kMaxArrayIndexSize) return false; |
uc32 ch = buffer->GetNext(); |
// If the string begins with a '0' character, it must only consist |
@@ -3918,8 +3918,16 @@ |
bool String::SlowAsArrayIndex(uint32_t* index) { |
- StringInputBuffer buffer(this); |
- return ComputeArrayIndex(&buffer, index, length()); |
+ if (length() <= kMaxCachedArrayIndexLength) { |
+ Hash(); // force computation of hash code |
bak
2008/10/22 13:25:14
Capitalize to Force and add period.
|
+ uint32_t field = length_field(); |
+ if ((field & kIsArrayIndexMask) == 0) return false; |
+ *index = (field & ((1 << kShortLengthShift) - 1)) >> kLongLengthShift; |
+ return true; |
+ } else { |
+ StringInputBuffer buffer(this); |
+ return ComputeArrayIndex(&buffer, index, length()); |
+ } |
} |
@@ -3956,18 +3964,21 @@ |
// Very long strings have a trivial hash that doesn't inspect the |
// string contents. |
- if (hasher.has_trivial_hash()) |
+ if (hasher.has_trivial_hash()) { |
return hasher.GetHashField(); |
+ } |
// Do the iterative array index computation as long as there is a |
// chance this is an array index. |
- while (buffer->has_more() && hasher.is_array_index()) |
+ while (buffer->has_more() && hasher.is_array_index()) { |
hasher.AddCharacter(buffer->GetNext()); |
+ } |
// Process the remaining characters without updating the array |
// index. |
- while (buffer->has_more()) |
+ while (buffer->has_more()) { |
hasher.AddCharacterNoIndex(buffer->GetNext()); |
+ } |
return hasher.GetHashField(); |
} |