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

Unified Diff: src/objects-inl.h

Issue 8143018: Revert "Added ability to lock strings to prevent their representation or encoding from changing." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 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.cc ('k') | src/runtime.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 6509f136caede0ac754f6053ae0a91ce67578933..c579d373f7207416134bfd8d47dd7f8a539c9e90 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -37,7 +37,6 @@
#include "elements.h"
#include "objects.h"
-#include "char-predicates-inl.h"
#include "contexts.h"
#include "conversions-inl.h"
#include "heap.h"
@@ -4218,6 +4217,7 @@ StringHasher::StringHasher(int length)
raw_running_hash_(0),
array_index_(0),
is_array_index_(0 < length_ && length_ <= String::kMaxArrayIndexSize),
+ is_first_char_(true),
is_valid_(true) { }
@@ -4229,18 +4229,26 @@ bool StringHasher::has_trivial_hash() {
void StringHasher::AddCharacter(uc32 c) {
// Use the Jenkins one-at-a-time hash function to update the hash
// for the given character.
- raw_running_hash_ = (raw_running_hash_ + c) * 1025;
+ raw_running_hash_ += c;
+ raw_running_hash_ += (raw_running_hash_ << 10);
raw_running_hash_ ^= (raw_running_hash_ >> 6);
+ // Incremental array index computation.
if (is_array_index_) {
- // Incremental array index computation.
- unsigned digit = static_cast<unsigned>(c) - '0';
- if (digit > 9 || array_index_ > 429496729U - ((digit + 2) >> 3)) {
+ if (c < '0' || c > '9') {
is_array_index_ = false;
} else {
- array_index_ = array_index_ * 10 + digit;
- // Check for overflows or prefixed zeros (lengths > 0).
- if (array_index_ == 0 && length_ > 1) {
+ int d = c - '0';
+ if (is_first_char_) {
+ is_first_char_ = false;
+ if (c == '0' && length_ > 1) {
+ is_array_index_ = false;
+ return;
+ }
+ }
+ if (array_index_ > 429496729U - ((d + 2) >> 3)) {
is_array_index_ = false;
+ } else {
+ array_index_ = array_index_ * 10 + d;
}
}
}
@@ -4249,7 +4257,8 @@ void StringHasher::AddCharacter(uc32 c) {
void StringHasher::AddCharacterNoIndex(uc32 c) {
ASSERT(!is_array_index());
- raw_running_hash_ = (raw_running_hash_ + c) * 1025;
+ raw_running_hash_ += c;
+ raw_running_hash_ += (raw_running_hash_ << 10);
raw_running_hash_ ^= (raw_running_hash_ >> 6);
}
« no previous file with comments | « src/objects.cc ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698