Revision: 3162 Author: [email protected] Date: Wed Oct 28 06:10:36 2009 Log: Derive string size constants
* The maximum length of short and medium sized strings is now derived from other constants. * Remove the redundant String part of their names. Review URL: http://codereview.chromium.org/347002 http://code.google.com/p/v8/source/detail?r=3162 Modified: /branches/bleeding_edge/src/heap.cc /branches/bleeding_edge/src/objects-inl.h /branches/bleeding_edge/src/objects.cc /branches/bleeding_edge/src/objects.h /branches/bleeding_edge/src/string-stream.cc /branches/bleeding_edge/test/cctest/test-api.cc ======================================= --- /branches/bleeding_edge/src/heap.cc Tue Oct 27 04:54:01 2009 +++ /branches/bleeding_edge/src/heap.cc Wed Oct 28 06:10:36 2009 @@ -1810,10 +1810,10 @@ } Map* map; - if (length <= String::kMaxShortStringSize) { + if (length <= String::kMaxShortSize) { map = is_ascii ? short_cons_ascii_string_map() : short_cons_string_map(); - } else if (length <= String::kMaxMediumStringSize) { + } else if (length <= String::kMaxMediumSize) { map = is_ascii ? medium_cons_ascii_string_map() : medium_cons_string_map(); } else { @@ -1843,11 +1843,11 @@ } Map* map; - if (length <= String::kMaxShortStringSize) { + if (length <= String::kMaxShortSize) { map = buffer->IsAsciiRepresentation() ? short_sliced_ascii_string_map() : short_sliced_string_map(); - } else if (length <= String::kMaxMediumStringSize) { + } else if (length <= String::kMaxMediumSize) { map = buffer->IsAsciiRepresentation() ? medium_sliced_ascii_string_map() : medium_sliced_string_map(); @@ -1912,9 +1912,9 @@ ExternalAsciiString::Resource* resource) { Map* map; int length = resource->length(); - if (length <= String::kMaxShortStringSize) { + if (length <= String::kMaxShortSize) { map = short_external_ascii_string_map(); - } else if (length <= String::kMaxMediumStringSize) { + } else if (length <= String::kMaxMediumSize) { map = medium_external_ascii_string_map(); } else { map = long_external_ascii_string_map(); @@ -2659,18 +2659,18 @@ Map* map; if (is_ascii) { - if (chars <= String::kMaxShortStringSize) { + if (chars <= String::kMaxShortSize) { map = short_ascii_symbol_map(); - } else if (chars <= String::kMaxMediumStringSize) { + } else if (chars <= String::kMaxMediumSize) { map = medium_ascii_symbol_map(); } else { map = long_ascii_symbol_map(); } size = SeqAsciiString::SizeFor(chars); } else { - if (chars <= String::kMaxShortStringSize) { + if (chars <= String::kMaxShortSize) { map = short_symbol_map(); - } else if (chars <= String::kMaxMediumStringSize) { + } else if (chars <= String::kMaxMediumSize) { map = medium_symbol_map(); } else { map = long_symbol_map(); @@ -2720,9 +2720,9 @@ // Determine the map based on the string's length. Map* map; - if (length <= String::kMaxShortStringSize) { + if (length <= String::kMaxShortSize) { map = short_ascii_string_map(); - } else if (length <= String::kMaxMediumStringSize) { + } else if (length <= String::kMaxMediumSize) { map = medium_ascii_string_map(); } else { map = long_ascii_string_map(); @@ -2757,9 +2757,9 @@ // Determine the map based on the string's length. Map* map; - if (length <= String::kMaxShortStringSize) { + if (length <= String::kMaxShortSize) { map = short_string_map(); - } else if (length <= String::kMaxMediumStringSize) { + } else if (length <= String::kMaxMediumSize) { map = medium_string_map(); } else { map = long_string_map(); ======================================= --- /branches/bleeding_edge/src/objects-inl.h Tue Oct 27 08:38:49 2009 +++ /branches/bleeding_edge/src/objects-inl.h Wed Oct 28 06:10:36 2009 @@ -1907,9 +1907,9 @@ Map* ExternalAsciiString::StringMap(int length) { Map* map; // Number of characters: determines the map. - if (length <= String::kMaxShortStringSize) { + if (length <= String::kMaxShortSize) { map = Heap::short_external_ascii_string_map(); - } else if (length <= String::kMaxMediumStringSize) { + } else if (length <= String::kMaxMediumSize) { map = Heap::medium_external_ascii_string_map(); } else { map = Heap::long_external_ascii_string_map(); @@ -1921,9 +1921,9 @@ Map* ExternalAsciiString::SymbolMap(int length) { Map* map; // Number of characters: determines the map. - if (length <= String::kMaxShortStringSize) { + if (length <= String::kMaxShortSize) { map = Heap::short_external_ascii_symbol_map(); - } else if (length <= String::kMaxMediumStringSize) { + } else if (length <= String::kMaxMediumSize) { map = Heap::medium_external_ascii_symbol_map(); } else { map = Heap::long_external_ascii_symbol_map(); @@ -1946,9 +1946,9 @@ Map* ExternalTwoByteString::StringMap(int length) { Map* map; // Number of characters: determines the map. - if (length <= String::kMaxShortStringSize) { + if (length <= String::kMaxShortSize) { map = Heap::short_external_string_map(); - } else if (length <= String::kMaxMediumStringSize) { + } else if (length <= String::kMaxMediumSize) { map = Heap::medium_external_string_map(); } else { map = Heap::long_external_string_map(); @@ -1960,9 +1960,9 @@ Map* ExternalTwoByteString::SymbolMap(int length) { Map* map; // Number of characters: determines the map. - if (length <= String::kMaxShortStringSize) { + if (length <= String::kMaxShortSize) { map = Heap::short_external_symbol_map(); - } else if (length <= String::kMaxMediumStringSize) { + } else if (length <= String::kMaxMediumSize) { map = Heap::medium_external_symbol_map(); } else { map = Heap::long_external_symbol_map(); @@ -2976,7 +2976,7 @@ bool StringHasher::has_trivial_hash() { - return length_ > String::kMaxMediumStringSize; + return length_ > String::kMaxMediumSize; } ======================================= --- /branches/bleeding_edge/src/objects.cc Mon Oct 26 03:51:30 2009 +++ /branches/bleeding_edge/src/objects.cc Wed Oct 28 06:10:36 2009 @@ -839,7 +839,7 @@ void String::StringShortPrint(StringStream* accumulator) { int len = length(); - if (len > kMaxMediumStringSize) { + if (len > kMaxMediumSize) { accumulator->Add("<Very long string[%u]>", len); return; } @@ -4660,7 +4660,7 @@ uint32_t StringHasher::GetHashField() { ASSERT(is_valid()); - if (length_ <= String::kMaxShortStringSize) { + if (length_ <= String::kMaxShortSize) { uint32_t payload; if (is_array_index()) { payload = v8::internal::HashField(array_index(), true); @@ -4669,7 +4669,7 @@ } return (payload & ((1 << String::kShortLengthShift) - 1)) | (length_ << String::kShortLengthShift); - } else if (length_ <= String::kMaxMediumStringSize) { + } else if (length_ <= String::kMaxMediumSize) { uint32_t payload = v8::internal::HashField(GetHash(), false); return (payload & ((1 << String::kMediumLengthShift) - 1)) | (length_ << String::kMediumLengthShift); ======================================= --- /branches/bleeding_edge/src/objects.h Tue Oct 27 08:38:49 2009 +++ /branches/bleeding_edge/src/objects.h Wed Oct 28 06:10:36 2009 @@ -4070,10 +4070,8 @@ static const int kSize = kLengthOffset + kIntSize; // Notice: kSize is not pointer-size aligned if pointers are 64-bit. - // Limits on sizes of different types of strings. - static const int kMaxShortStringSize = 63; - static const int kMaxMediumStringSize = 16383; - + // Maximum number of characters to consider when trying to convert a string + // value into an array index. static const int kMaxArrayIndexSize = 10; // Max ascii char code. @@ -4097,13 +4095,17 @@ // field. static const int kMaxCachedArrayIndexLength = 7; - // Shift constants for retriving length and hash code from + // Shift constants for retrieving length and hash code from // length/hash field. static const int kHashShift = kNofLengthBitFields; static const int kShortLengthShift = kHashShift + kShortStringTag; static const int kMediumLengthShift = kHashShift + kMediumStringTag; static const int kLongLengthShift = kHashShift + kLongStringTag; - // Maximal string length that can be stored in the hash/length field. + + // Maximal string length that can be stored in the hash/length field for + // different types of strings. + static const int kMaxShortSize = (1 << (32 - kShortLengthShift)) - 1; + static const int kMaxMediumSize = (1 << (32 - kMediumLengthShift)) - 1; static const int kMaxLength = (1 << (32 - kLongLengthShift)) - 1; // Limit for truncation in short printing. ======================================= --- /branches/bleeding_edge/src/string-stream.cc Wed Sep 16 06:41:24 2009 +++ /branches/bleeding_edge/src/string-stream.cc Wed Oct 28 06:10:36 2009 @@ -188,7 +188,7 @@ void StringStream::PrintObject(Object* o) { o->ShortPrint(this); if (o->IsString()) { - if (String::cast(o)->length() <= String::kMaxMediumStringSize) { + if (String::cast(o)->length() <= String::kMaxMediumSize) { return; } } else if (o->IsNumber() || o->IsOddball()) { ======================================= --- /branches/bleeding_edge/test/cctest/test-api.cc Tue Oct 27 08:38:49 2009 +++ /branches/bleeding_edge/test/cctest/test-api.cc Wed Oct 28 06:10:36 2009 @@ -6958,7 +6958,7 @@ CHECK(string->map() == i::Heap::short_external_ascii_string_map() || string->map() == i::Heap::medium_external_ascii_string_map()); // Morph external string to be TwoByte string. - if (string->length() <= i::String::kMaxShortStringSize) { + if (string->length() <= i::String::kMaxShortSize) { string->set_map(i::Heap::short_external_string_map()); } else { string->set_map(i::Heap::medium_external_string_map()); @@ -6971,7 +6971,7 @@ CHECK(string->map() == i::Heap::short_external_string_map() || string->map() == i::Heap::medium_external_string_map()); // Morph external string to be ASCII string. - if (string->length() <= i::String::kMaxShortStringSize) { + if (string->length() <= i::String::kMaxShortSize) { string->set_map(i::Heap::short_external_ascii_string_map()); } else { string->set_map(i::Heap::medium_external_ascii_string_map()); --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---
