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);
}
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();
}
+#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
__ 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;
// 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.
}
+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();
// 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.
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");