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

Unified Diff: src/objects-inl.h

Issue 7977001: 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: Fix bug in test when running threaded. Created 9 years, 3 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 3b63f9c28b2f239c7909ef0dba7c3d8f953ccc2a..a63ac6c4449c69d6b1b78e70f9ab625b8145c81d 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -37,6 +37,7 @@
#include "elements.h"
#include "objects.h"
+#include "char-predicates-inl.h"
#include "contexts.h"
#include "conversions-inl.h"
#include "heap.h"
@@ -4194,7 +4195,6 @@ 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) { }
@@ -4206,26 +4206,18 @@ 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_ += c;
- raw_running_hash_ += (raw_running_hash_ << 10);
+ raw_running_hash_ = (raw_running_hash_ + c) * 1025;
raw_running_hash_ ^= (raw_running_hash_ >> 6);
- // Incremental array index computation.
if (is_array_index_) {
- if (c < '0' || c > '9') {
+ // Incremental array index computation.
+ unsigned digit = static_cast<unsigned>(c) - '0';
+ if (digit > 9 || array_index_ > 429496729U - ((digit + 2) >> 3)) {
is_array_index_ = false;
} else {
- 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)) {
+ array_index_ = array_index_ * 10 + digit;
+ // Check for overflows or prefixed zeros (lengths > 0).
+ if (array_index_ == 0 && length_ > 1) {
is_array_index_ = false;
- } else {
- array_index_ = array_index_ * 10 + d;
}
}
}
@@ -4234,8 +4226,7 @@ void StringHasher::AddCharacter(uc32 c) {
void StringHasher::AddCharacterNoIndex(uc32 c) {
ASSERT(!is_array_index());
- raw_running_hash_ += c;
- raw_running_hash_ += (raw_running_hash_ << 10);
+ raw_running_hash_ = (raw_running_hash_ + c) * 1025;
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