Commit 9569b20d authored by yangguo@chromium.org's avatar yangguo@chromium.org

Replace the use CharacterStreams in Heap::AllocateSymbolInternal and String::ComputeHash

R=yangguo@chromium.org
BUG=

Review URL: https://chromiumcodereview.appspot.com/11593007
Patch from Dan Carney <dcarney@google.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13242 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 362218a0
......@@ -98,12 +98,34 @@ MaybeObject* Heap::AllocateStringFromUtf8(Vector<const char> str,
}
template<>
bool inline Heap::IsOneByte(Vector<const char> str, int chars) {
// TODO(dcarney): incorporate Latin-1 check when Latin-1 is supported?
// ASCII only check.
return chars == str.length();
}
template<>
bool inline Heap::IsOneByte(String* str, int chars) {
return str->IsOneByteRepresentation();
}
MaybeObject* Heap::AllocateSymbol(Vector<const char> str,
int chars,
uint32_t hash_field) {
unibrow::Utf8InputBuffer<> buffer(str.start(),
static_cast<unsigned>(str.length()));
return AllocateInternalSymbol(&buffer, chars, hash_field);
if (IsOneByte(str, chars)) return AllocateAsciiSymbol(str, hash_field);
return AllocateInternalSymbol<false>(str, chars, hash_field);
}
template<typename T>
MaybeObject* Heap::AllocateInternalSymbol(T t, int chars, uint32_t hash_field) {
if (IsOneByte(t, chars)) {
return AllocateInternalSymbol<true>(t, chars, hash_field);
}
return AllocateInternalSymbol<false>(t, chars, hash_field);
}
......
......@@ -3302,8 +3302,8 @@ static inline bool Between(uint32_t character, uint32_t from, uint32_t to) {
MUST_USE_RESULT static inline MaybeObject* MakeOrFindTwoCharacterString(
Heap* heap,
uint32_t c1,
uint32_t c2) {
uint16_t c1,
uint16_t c2) {
String* symbol;
// Numeric strings have a different hash algorithm not known by
// LookupTwoCharsSymbolIfExists, so we skip this step for such strings.
......@@ -3352,8 +3352,8 @@ MaybeObject* Heap::AllocateConsString(String* first, String* second) {
// dictionary. Check whether we already have the string in the symbol
// table to prevent creation of many unneccesary strings.
if (length == 2) {
unsigned c1 = first->Get(0);
unsigned c2 = second->Get(0);
uint16_t c1 = first->Get(0);
uint16_t c2 = second->Get(0);
return MakeOrFindTwoCharacterString(this, c1, c2);
}
......@@ -3467,8 +3467,8 @@ MaybeObject* Heap::AllocateSubString(String* buffer,
// Optimization for 2-byte strings often used as keys in a decompression
// dictionary. Check whether we already have the string in the symbol
// table to prevent creation of many unneccesary strings.
unsigned c1 = buffer->Get(start);
unsigned c2 = buffer->Get(start + 1);
uint16_t c1 = buffer->Get(start);
uint16_t c2 = buffer->Get(start + 1);
return MakeOrFindTwoCharacterString(this, c1, c2);
}
......@@ -4624,27 +4624,88 @@ Map* Heap::SymbolMapForString(String* string) {
}
MaybeObject* Heap::AllocateInternalSymbol(unibrow::CharacterStream* buffer,
int chars,
uint32_t hash_field) {
ASSERT(chars >= 0);
// Ensure the chars matches the number of characters in the buffer.
ASSERT(static_cast<unsigned>(chars) == buffer->Utf16Length());
// Determine whether the string is ASCII.
bool is_ascii = true;
while (buffer->has_more()) {
if (buffer->GetNext() > unibrow::Utf8::kMaxOneByteChar) {
is_ascii = false;
break;
template<typename T>
class AllocateInternalSymbolHelper {
public:
static void WriteOneByteData(T t, char* chars, int len);
static void WriteTwoByteData(T t, uint16_t* chars, int len);
private:
DISALLOW_COPY_AND_ASSIGN(AllocateInternalSymbolHelper);
};
template<>
class AllocateInternalSymbolHelper< Vector<const char> > {
public:
static inline void WriteOneByteData(Vector<const char> vector,
char* chars,
int len) {
// Only works for ascii.
ASSERT(vector.length() == len);
memcpy(chars, vector.start(), len);
}
static inline void WriteTwoByteData(Vector<const char> vector,
uint16_t* chars,
int len) {
const uint8_t* stream = reinterpret_cast<const uint8_t*>(vector.start());
unsigned stream_length = vector.length();
while (stream_length != 0) {
unsigned consumed = 0;
uint32_t c = unibrow::Utf8::ValueOf(stream, stream_length, &consumed);
ASSERT(c != unibrow::Utf8::kBadChar);
ASSERT(consumed <= stream_length);
stream_length -= consumed;
stream += consumed;
if (c > unibrow::Utf16::kMaxNonSurrogateCharCode) {
len -= 2;
if (len < 0) break;
*chars++ = unibrow::Utf16::LeadSurrogate(c);
*chars++ = unibrow::Utf16::TrailSurrogate(c);
} else {
len -= 1;
if (len < 0) break;
*chars++ = c;
}
}
ASSERT(stream_length == 0);
ASSERT(len == 0);
}
buffer->Rewind();
private:
DISALLOW_COPY_AND_ASSIGN(AllocateInternalSymbolHelper);
};
template<>
class AllocateInternalSymbolHelper<String*> {
public:
static inline void WriteOneByteData(String* s, char* chars, int len) {
ASSERT(s->length() == len);
String::WriteToFlat(s, chars, 0, len);
}
static inline void WriteTwoByteData(String* s, uint16_t* chars, int len) {
ASSERT(s->length() == len);
String::WriteToFlat(s, chars, 0, len);
}
private:
DISALLOW_COPY_AND_ASSIGN(AllocateInternalSymbolHelper<String*>);
};
template<bool is_one_byte, typename T>
MaybeObject* Heap::AllocateInternalSymbol(T t,
int chars,
uint32_t hash_field) {
typedef AllocateInternalSymbolHelper<T> H;
ASSERT(chars >= 0);
// Compute map and object size.
int size;
Map* map;
if (is_ascii) {
if (is_one_byte) {
if (chars > SeqOneByteString::kMaxLength) {
return Failure::OutOfMemoryException();
}
......@@ -4674,21 +4735,26 @@ MaybeObject* Heap::AllocateInternalSymbol(unibrow::CharacterStream* buffer,
ASSERT_EQ(size, answer->Size());
// Fill in the characters.
int i = 0;
while (i < chars) {
uint32_t character = buffer->GetNext();
if (character > unibrow::Utf16::kMaxNonSurrogateCharCode) {
answer->Set(i++, unibrow::Utf16::LeadSurrogate(character));
answer->Set(i++, unibrow::Utf16::TrailSurrogate(character));
} else {
answer->Set(i++, character);
}
if (is_one_byte) {
H::WriteOneByteData(t, SeqOneByteString::cast(answer)->GetChars(), chars);
} else {
H::WriteTwoByteData(t, SeqTwoByteString::cast(answer)->GetChars(), chars);
}
return answer;
}
// Need explicit instantiations.
template
MaybeObject* Heap::AllocateInternalSymbol<true>(String*, int, uint32_t);
template
MaybeObject* Heap::AllocateInternalSymbol<false>(String*, int, uint32_t);
template
MaybeObject* Heap::AllocateInternalSymbol<false>(Vector<const char>,
int,
uint32_t);
MaybeObject* Heap::AllocateRawOneByteString(int length,
PretenureFlag pretenure) {
if (length < 0 || length > SeqOneByteString::kMaxLength) {
......
......@@ -764,12 +764,16 @@ class Heap {
Vector<const uc16> str,
uint32_t hash_field);
MUST_USE_RESULT MaybeObject* AllocateInternalSymbol(
unibrow::CharacterStream* buffer, int chars, uint32_t hash_field);
template<typename T>
static inline bool IsOneByte(T t, int chars);
MUST_USE_RESULT MaybeObject* AllocateExternalSymbol(
Vector<const char> str,
int chars);
template<typename T>
MUST_USE_RESULT inline MaybeObject* AllocateInternalSymbol(
T t, int chars, uint32_t hash_field);
template<bool is_one_byte, typename T>
MUST_USE_RESULT MaybeObject* AllocateInternalSymbol(
T t, int chars, uint32_t hash_field);
// Allocates and partially initializes a String. There are two String
// encodings: ASCII and two byte. These functions allocate a string of the
......
......@@ -631,7 +631,17 @@ Handle<String> JsonParser<seq_ascii>::ScanJsonString() {
position_);
}
if (c0 < 0x20) return Handle<String>::null();
running_hash = StringHasher::AddCharacterCore(running_hash, c0);
if (static_cast<uint32_t>(c0) >
unibrow::Utf16::kMaxNonSurrogateCharCode) {
running_hash =
StringHasher::AddCharacterCore(running_hash,
unibrow::Utf16::LeadSurrogate(c0));
running_hash =
StringHasher::AddCharacterCore(running_hash,
unibrow::Utf16::TrailSurrogate(c0));
} else {
running_hash = StringHasher::AddCharacterCore(running_hash, c0);
}
position++;
if (position >= source_length_) return Handle<String>::null();
c0 = seq_source_->SeqOneByteStringGet(position);
......
......@@ -2584,8 +2584,7 @@ void String::Visit(
case kConsStringTag | kOneByteStringTag:
case kConsStringTag | kTwoByteStringTag:
string = cons_op.Operate(ConsString::cast(string), &offset, &type,
&length);
string = cons_op.Operate(string, &offset, &type, &length);
if (string == NULL) return;
slice_offset = offset;
ASSERT(length == static_cast<unsigned>(string->length()));
......@@ -2777,6 +2776,11 @@ const uint16_t* ExternalTwoByteString::ExternalTwoByteStringGetData(
}
String* ConsStringNullOp::Operate(String*, unsigned*, int32_t*, unsigned*) {
return NULL;
}
unsigned ConsStringIteratorOp::OffsetForDepth(unsigned depth) {
return depth & kDepthMask;
}
......@@ -2805,42 +2809,38 @@ void ConsStringIteratorOp::Pop() {
}
void ConsStringIteratorOp::Reset() {
depth_ = 0;
maximum_depth_ = 0;
bool ConsStringIteratorOp::HasMore() {
return depth_ != 0;
}
bool ConsStringIteratorOp::HasMore() {
return depth_ != 0;
void ConsStringIteratorOp::Reset() {
depth_ = 0;
}
bool ConsStringIteratorOp::ContinueOperation(ContinueResponse* response) {
String* ConsStringIteratorOp::ContinueOperation(int32_t* type_out,
unsigned* length_out) {
bool blew_stack;
int32_t type;
unsigned length;
String* string = NextLeaf(&blew_stack, &type, &length);
String* string = NextLeaf(&blew_stack, type_out, length_out);
// String found.
if (string != NULL) {
consumed_ += length;
response->string_ = string;
response->offset_ = 0;
response->length_ = length;
response->type_ = type;
return true;
// Verify output.
ASSERT(*length_out == static_cast<unsigned>(string->length()));
ASSERT(*type_out == string->map()->instance_type());
return string;
}
// Traversal complete.
if (!blew_stack) return false;
// Restart search.
Reset();
// TODO(dcarney) This is unnecessary.
// After a reset, we don't need a String::Visit
response->string_ = root_;
response->offset_ = consumed_;
response->length_ = root_length_;
response->type_ = root_type_;
return true;
if (!blew_stack) return NULL;
// Restart search from root.
unsigned offset_out;
string = Search(&offset_out, type_out, length_out);
// Verify output.
ASSERT(string == NULL || offset_out == 0);
ASSERT(string == NULL ||
*length_out == static_cast<unsigned>(string->length()));
ASSERT(string == NULL || *type_out == string->map()->instance_type());
return string;
}
......@@ -2857,18 +2857,24 @@ StringCharacterStream::StringCharacterStream(
end_(NULL),
op_(op) {
op->Reset();
String::Visit(string,
offset, *this, *op, string->map()->instance_type(), string->length());
int32_t type = string->map()->instance_type();
unsigned length = string->length();
String::Visit(string, offset, *this, *op, type, length);
}
bool StringCharacterStream::HasMore() {
if (buffer8_ != end_) return true;
if (!op_->HasMore()) return false;
ConsStringIteratorOp::ContinueResponse response;
if (!op_->ContinueOperation(&response)) return false;
String::Visit(response.string_,
response.offset_, *this, *op_, response.type_, response.length_);
unsigned length;
int32_t type;
String* string = op_->ContinueOperation(&type, &length);
if (string == NULL) return false;
ASSERT(!string->IsConsString());
ASSERT(string->length() != 0);
ConsStringNullOp null_op;
String::Visit(string, 0, *this, null_op, type, length);
ASSERT(buffer8_ != end_);
return true;
}
......@@ -5138,7 +5144,7 @@ bool StringHasher::has_trivial_hash() {
}
uint32_t StringHasher::AddCharacterCore(uint32_t running_hash, uint32_t c) {
uint32_t StringHasher::AddCharacterCore(uint32_t running_hash, uint16_t c) {
running_hash += c;
running_hash += (running_hash << 10);
running_hash ^= (running_hash >> 6);
......@@ -5157,66 +5163,62 @@ uint32_t StringHasher::GetHashCore(uint32_t running_hash) {
}
void StringHasher::AddCharacter(uint32_t c) {
if (c > unibrow::Utf16::kMaxNonSurrogateCharCode) {
AddSurrogatePair(c); // Not inlined.
return;
}
void StringHasher::AddCharacter(uint16_t c) {
// Use the Jenkins one-at-a-time hash function to update the hash
// for the given character.
raw_running_hash_ = AddCharacterCore(raw_running_hash_, c);
// Incremental array index computation.
if (is_array_index_) {
if (c < '0' || c > '9') {
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)) {
is_array_index_ = false;
} else {
array_index_ = array_index_ * 10 + d;
}
}
}
}
void StringHasher::AddCharacterNoIndex(uint32_t c) {
ASSERT(!is_array_index());
if (c > unibrow::Utf16::kMaxNonSurrogateCharCode) {
AddSurrogatePairNoIndex(c); // Not inlined.
return;
bool StringHasher::UpdateIndex(uint16_t c) {
ASSERT(is_array_index_);
if (c < '0' || c > '9') {
is_array_index_ = false;
return false;
}
raw_running_hash_ = AddCharacterCore(raw_running_hash_, c);
int d = c - '0';
if (is_first_char_) {
is_first_char_ = false;
if (c == '0' && length_ > 1) {
is_array_index_ = false;
return false;
}
}
if (array_index_ > 429496729U - ((d + 2) >> 3)) {
is_array_index_ = false;
return false;
}
array_index_ = array_index_ * 10 + d;
return true;
}
uint32_t StringHasher::GetHash() {
// Get the calculated raw hash value and do some more bit ops to distribute
// the hash further. Ensure that we never return zero as the hash value.
return GetHashCore(raw_running_hash_);
template<typename Char>
inline void StringHasher::AddCharacters(const Char* chars, int length) {
ASSERT(sizeof(Char) == 1 || sizeof(Char) == 2);
int i = 0;
if (is_array_index_) {
for (; i < length; i++) {
AddCharacter(chars[i]);
if (!UpdateIndex(chars[i])) {
i++;
break;
}
}
}
for (; i < length; i++) {
ASSERT(!is_array_index_);
AddCharacter(chars[i]);
}
}
template <typename schar>
uint32_t HashSequentialString(const schar* chars, int length, uint32_t seed) {
uint32_t StringHasher::HashSequentialString(const schar* chars,
int length,
uint32_t seed) {
StringHasher hasher(length, seed);
if (!hasher.has_trivial_hash()) {
int i;
for (i = 0; hasher.is_array_index() && (i < length); i++) {
hasher.AddCharacter(chars[i]);
}
for (; i < length; i++) {
hasher.AddCharacterNoIndex(chars[i]);
}
}
if (!hasher.has_trivial_hash()) hasher.AddCharacters(chars, length);
return hasher.GetHashField();
}
......
This diff is collapsed.
......@@ -3043,7 +3043,7 @@ class SymbolTable: public HashTable<SymbolTableShape, HashTableKey*> {
// true if it is found, assigning the symbol to the given output
// parameter.
bool LookupSymbolIfExists(String* str, String** symbol);
bool LookupTwoCharsSymbolIfExists(uint32_t c1, uint32_t c2, String** symbol);
bool LookupTwoCharsSymbolIfExists(uint16_t c1, uint16_t c2, String** symbol);
// Casting.
static inline SymbolTable* cast(Object* obj);
......@@ -6929,30 +6929,14 @@ class StringHasher {
public:
explicit inline StringHasher(int length, uint32_t seed);
// Returns true if the hash of this string can be computed without
// looking at the contents.
inline bool has_trivial_hash();
// Add a character to the hash and update the array index calculation.
inline void AddCharacter(uint32_t c);
template <typename schar>
static inline uint32_t HashSequentialString(const schar* chars,
int length,
uint32_t seed);
// Adds a character to the hash but does not update the array index
// calculation. This can only be called when it has been verified
// that the input is not an array index.
inline void AddCharacterNoIndex(uint32_t c);
// Add a character above 0xffff as a surrogate pair. These can get into
// the hasher through the routines that take a UTF-8 string and make a symbol.
void AddSurrogatePair(uc32 c);
void AddSurrogatePairNoIndex(uc32 c);
// Returns the value to store in the hash field of a string with
// the given length and contents.
uint32_t GetHashField();
// Returns true if the characters seen so far make up a legal array
// index.
bool is_array_index() { return is_array_index_; }
static uint32_t ComputeHashField(unibrow::CharacterStream* buffer,
int length,
uint32_t seed);
// Calculated hash value for a string consisting of 1 to
// String::kMaxArrayIndexSize digits with no leading zeros (except "0").
......@@ -6964,51 +6948,36 @@ class StringHasher {
// use 27 instead.
static const int kZeroHash = 27;
private:
uint32_t array_index() {
ASSERT(is_array_index());
return array_index_;
}
inline uint32_t GetHash();
// Reusable parts of the hashing algorithm.
INLINE(static uint32_t AddCharacterCore(uint32_t running_hash, uint32_t c));
INLINE(static uint32_t AddCharacterCore(uint32_t running_hash, uint16_t c));
INLINE(static uint32_t GetHashCore(uint32_t running_hash));
int length_;
uint32_t raw_running_hash_;
uint32_t array_index_;
bool is_array_index_;
bool is_first_char_;
friend class TwoCharHashTableKey;
template <bool seq_ascii> friend class JsonParser;
};
class IncrementalAsciiStringHasher {
public:
explicit inline IncrementalAsciiStringHasher(uint32_t seed, char first_char);
inline void AddCharacter(uc32 c);
inline uint32_t GetHash();
protected:
// Returns the value to store in the hash field of a string with
// the given length and contents.
uint32_t GetHashField();
// Returns true if the hash of this string can be computed without
// looking at the contents.
inline bool has_trivial_hash();
// Adds a block of characters to the hash.
template<typename Char>
inline void AddCharacters(const Char* chars, int len);
private:
// Add a character to the hash.
inline void AddCharacter(uint16_t c);
// Update index. Returns true if string is still an index.
inline bool UpdateIndex(uint16_t c);
int length_;
uint32_t raw_running_hash_;
uint32_t array_index_;
bool is_array_index_;
char first_char_;
bool is_first_char_;
DISALLOW_COPY_AND_ASSIGN(StringHasher);
};
// Calculates string hash.
template <typename schar>
inline uint32_t HashSequentialString(const schar* chars,
int length,
uint32_t seed);
// The characteristics of a string are stored in its map. Retrieving these
// few bits of information is moderately expensive, involving two memory
// loads where the second is dependent on the first. To improve efficiency
......@@ -7227,10 +7196,6 @@ class String: public HeapObject {
// Returns a hash value used for the property table
inline uint32_t Hash();
static uint32_t ComputeHashField(unibrow::CharacterStream* buffer,
int length,
uint32_t seed);
static bool ComputeArrayIndex(unibrow::CharacterStream* buffer,
uint32_t* index,
int length);
......@@ -7870,22 +7835,30 @@ class StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> {
};
// A ConsStringOp that returns null.
// Useful when the operation to apply on a ConsString
// requires an expensive data structure.
class ConsStringNullOp {
public:
inline ConsStringNullOp() {}
static inline String* Operate(String*, unsigned*, int32_t*, unsigned*);
private:
DISALLOW_COPY_AND_ASSIGN(ConsStringNullOp);
};
// This maintains an off-stack representation of the stack frames required
// to traverse a ConsString, allowing an entirely iterative and restartable
// traversal of the entire string
// Note: this class is not GC-safe.
class ConsStringIteratorOp {
public:
struct ContinueResponse {
String* string_;
unsigned offset_;
unsigned length_;
int32_t type_;
};
inline ConsStringIteratorOp() {}
String* Operate(ConsString* cons_string, unsigned* offset_out,
int32_t* type_out, unsigned* length_out);
inline bool ContinueOperation(ContinueResponse* response);
String* Operate(String* string,
unsigned* offset_out,
int32_t* type_out,
unsigned* length_out);
inline String* ContinueOperation(int32_t* type_out, unsigned* length_out);
inline void Reset();
inline bool HasMore();
......@@ -7902,6 +7875,9 @@ class ConsStringIteratorOp {
inline void AdjustMaximumDepth();
inline void Pop();
String* NextLeaf(bool* blew_stack, int32_t* type_out, unsigned* length_out);
String* Search(unsigned* offset_out,
int32_t* type_out,
unsigned* length_out);
unsigned depth_;
unsigned maximum_depth_;
......@@ -7910,8 +7886,6 @@ class ConsStringIteratorOp {
ConsString* frames_[kStackSize];
unsigned consumed_;
ConsString* root_;
int32_t root_type_;
unsigned root_length_;
DISALLOW_COPY_AND_ASSIGN(ConsStringIteratorOp);
};
......@@ -7919,8 +7893,9 @@ class ConsStringIteratorOp {
// Note: this class is not GC-safe.
class StringCharacterStream {
public:
inline StringCharacterStream(
String* string, unsigned offset, ConsStringIteratorOp* op);
inline StringCharacterStream(String* string,
unsigned offset,
ConsStringIteratorOp* op);
inline uint16_t GetNext();
inline bool HasMore();
inline void Reset(String* string, unsigned offset, ConsStringIteratorOp* op);
......
......@@ -112,7 +112,7 @@ const char* StringsStorage::GetCopy(const char* src) {
OS::StrNCpy(dst, src, len);
dst[len] = '\0';
uint32_t hash =
HashSequentialString(dst.start(), len, HEAP->HashSeed());
StringHasher::HashSequentialString(dst.start(), len, HEAP->HashSeed());
return AddOrDisposeString(dst.start(), hash);
}
......@@ -145,7 +145,7 @@ const char* StringsStorage::GetVFormatted(const char* format, va_list args) {
DeleteArray(str.start());
return format;
}
uint32_t hash = HashSequentialString(
uint32_t hash = StringHasher::HashSequentialString(
str.start(), len, HEAP->HashSeed());
return AddOrDisposeString(str.start(), hash);
}
......@@ -156,8 +156,8 @@ const char* StringsStorage::GetName(String* name) {
int length = Min(kMaxNameSize, name->length());
SmartArrayPointer<char> data =
name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL, 0, length);
uint32_t hash =
HashSequentialString(*data, length, name->GetHeap()->HashSeed());
uint32_t hash = StringHasher::HashSequentialString(
*data, length, name->GetHeap()->HashSeed());
return AddOrDisposeString(data.Detach(), hash);
}
return "";
......@@ -1451,9 +1451,9 @@ void HeapObjectsMap::RemoveDeadEntries() {
SnapshotObjectId HeapObjectsMap::GenerateId(v8::RetainedObjectInfo* info) {
SnapshotObjectId id = static_cast<SnapshotObjectId>(info->GetHash());
const char* label = info->GetLabel();
id ^= HashSequentialString(label,
static_cast<int>(strlen(label)),
HEAP->HashSeed());
id ^= StringHasher::HashSequentialString(label,
static_cast<int>(strlen(label)),
HEAP->HashSeed());
intptr_t element_count = info->GetElementCount();
if (element_count != -1)
id ^= ComputeIntegerHash(static_cast<uint32_t>(element_count),
......@@ -2940,9 +2940,10 @@ class NativeGroupRetainedObjectInfo : public v8::RetainedObjectInfo {
NativeGroupRetainedObjectInfo* NativeObjectsExplorer::FindOrAddGroupInfo(
const char* label) {
const char* label_copy = collection_->names()->GetCopy(label);
uint32_t hash = HashSequentialString(label_copy,
static_cast<int>(strlen(label_copy)),
HEAP->HashSeed());
uint32_t hash = StringHasher::HashSequentialString(
label_copy,
static_cast<int>(strlen(label_copy)),
HEAP->HashSeed());
HashMap::Entry* entry = native_groups_.Lookup(const_cast<char*>(label_copy),
hash, true);
if (entry->value == NULL) {
......
......@@ -170,10 +170,6 @@ class Utf8 {
// that match are coded as a 4 byte UTF-8 sequence.
static const unsigned kBytesSavedByCombiningSurrogates = 2;
static const unsigned kSizeOfUnmatchedSurrogate = 3;
private:
template <unsigned s> friend class Utf8InputBuffer;
friend class Test;
static inline uchar ValueOf(const byte* str,
unsigned length,
unsigned* cursor);
......
......@@ -345,37 +345,24 @@ void AccumulateStats(Handle<String> cons_string, ConsStringStats* stats) {
void AccumulateStatsWithOperator(
ConsString* cons_string, ConsStringStats* stats) {
// Init op.
unsigned offset = 0;
int32_t type = cons_string->map()->instance_type();
unsigned length = static_cast<unsigned>(cons_string->length());
ConsStringIteratorOp op;
op.Reset();
// Use response for initial search and on blown stack.
ConsStringIteratorOp::ContinueResponse response;
response.string_ = cons_string;
response.offset_ = 0;
response.type_ = cons_string->map()->instance_type();
response.length_ = (uint32_t) cons_string->length();
String* string = op.Operate(cons_string, &offset, &type, &length);
CHECK(string != NULL);
while (true) {
String* string = op.Operate(ConsString::cast(response.string_),
&response.offset_,
&response.type_,
&response.length_);
CHECK(string != NULL);
while (true) {
// Accumulate stats.
stats->leaves_++;
stats->chars_ += string->length();
// Check for completion.
bool keep_going_fast_check = op.HasMore();
bool keep_going = op.ContinueOperation(&response);
if (!keep_going) return;
// Verify no false positives for fast check.
CHECK(keep_going_fast_check);
CHECK(response.string_ != NULL);
// Blew stack. Restart outer loop.
if (response.string_->IsConsString()) break;
string = response.string_;
}
};
ASSERT(!string->IsConsString());
// Accumulate stats.
stats->leaves_++;
stats->chars_ += string->length();
// Check for completion.
bool keep_going_fast_check = op.HasMore();
string = op.ContinueOperation(&type, &length);
if (string == NULL) return;
// Verify no false positives for fast check.
CHECK(keep_going_fast_check);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment