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

Unified Diff: src/objects.cc

Issue 7869: Apply Daniel's patch for array index strings. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« 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