Commit 6e00a803 authored by erik.corry@gmail.com's avatar erik.corry@gmail.com

You can't use BinarySearch on an unsorted array and other

sillinesses found while trying to get rid of medium-sized strings.


git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@595 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent f26baa4a
......@@ -524,7 +524,7 @@ Handle<DescriptorArray> Factory::CopyAppendCallbackDescriptors(
Handle<String> key =
SymbolFromString(Handle<String>(String::cast(entry->name())));
// Check if a descriptor with this name already exists before writing.
if (result->BinarySearch(*key, 0, descriptor_count - 1) ==
if (result->LinearSearch(*key, descriptor_count) ==
DescriptorArray::kNotFound) {
CallbacksDescriptor desc(*key, *entry, entry->property_attributes());
w.Write(&desc);
......
......@@ -1936,17 +1936,17 @@ Map* Heap::SymbolMapForString(String* string) {
}
if (map == short_sliced_string_map()) return short_sliced_symbol_map();
if (map == medium_sliced_string_map()) return short_sliced_symbol_map();
if (map == long_sliced_string_map()) return short_sliced_symbol_map();
if (map == medium_sliced_string_map()) return medium_sliced_symbol_map();
if (map == long_sliced_string_map()) return long_sliced_symbol_map();
if (map == short_sliced_ascii_string_map()) {
return short_sliced_ascii_symbol_map();
}
if (map == medium_sliced_ascii_string_map()) {
return short_sliced_ascii_symbol_map();
return medium_sliced_ascii_symbol_map();
}
if (map == long_sliced_ascii_string_map()) {
return short_sliced_ascii_symbol_map();
return long_sliced_ascii_symbol_map();
}
if (map == short_external_string_map()) return short_external_string_map();
......
......@@ -206,6 +206,18 @@ void LoadIC::GenerateFunctionPrototype(MacroAssembler* masm) {
}
#ifdef DEBUG
// For use in assert below.
static int TenToThe(int exponent) {
ASSERT(exponent <= 9);
ASSERT(exponent >= 1);
int answer = 10;
for (int i = 1; i < exponent; i++) answer *= 10;
return answer;
}
#endif
void KeyedLoadIC::GenerateGeneric(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- esp[0] : return address
......@@ -262,6 +274,11 @@ void KeyedLoadIC::GenerateGeneric(MacroAssembler* masm) {
__ IncrementCounter(&Counters::keyed_load_generic_symbol, 1);
__ ret(0);
// Array index string: If short enough use cache in length/hash field (ebx).
// We assert that there are enough bits in an int32_t after the hash shift
// bits have been subtracted to allow space for the length and the cached
// array index.
ASSERT(TenToThe(String::kMaxCachedArrayIndexLength) <
(1 << (String::kShortLengthShift - String::kHashShift)));
__ bind(&index_string);
const int kLengthFieldLimit =
(String::kMaxCachedArrayIndexLength + 1) << String::kShortLengthShift;
......
......@@ -1130,10 +1130,7 @@ int DescriptorArray::Search(String* name) {
// Fast case: do linear search for small arrays.
const int kMaxElementsForLinearSearch = 8;
if (name->IsSymbol() && nof < kMaxElementsForLinearSearch) {
for (int number = 0; number < nof; number++) {
if (name == GetKey(number)) return number;
}
return kNotFound;
return LinearSearch(name, nof);
}
// Slow case: perform binary search.
......
......@@ -2877,6 +2877,14 @@ int DescriptorArray::BinarySearch(String* name, int low, int high) {
}
int DescriptorArray::LinearSearch(String* name, int len) {
for (int number = 0; number < len; number++) {
if (name->Equals(GetKey(number))) return number;
}
return kNotFound;
}
#ifdef DEBUG
bool DescriptorArray::IsEqualTo(DescriptorArray* other) {
if (IsEmpty()) return other->IsEmpty();
......
......@@ -1629,6 +1629,10 @@ class DescriptorArray: public FixedArray {
// with low=0 and high=2.
int BinarySearch(String* name, int low, int high);
// Perform a linear search in the instance descriptors represented
// by this fixed array. len is the number of descriptor indeces that are
// valid. Does not require the descriptors to be sorted.
int LinearSearch(String* name, int len);
// Allocates a DescriptorArray, but returns the singleton
// empty descriptor array object if number_of_descriptors is 0.
......
......@@ -81,18 +81,12 @@ assertFalse(NaN in a);
assertFalse(Infinity in a);
assertFalse(-Infinity in a);
/*****
* NOTE: Two of the tests below are disabled due to a bug in V8.
* Fast case (non-dictionary) sparse arrays do not work as advertised.
*
*/
var a = [];
a[1] = 2;
//assertFalse(0 in a);
assertFalse(0 in a);
assertTrue(1 in a);
assertFalse(2 in a);
//assertFalse('0' in a);
assertFalse('0' in a);
assertTrue('1' in a);
assertFalse('2' in a);
assertTrue('toString' in a, "toString");
......
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