OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 6544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6555 }; | 6555 }; |
6556 | 6556 |
6557 | 6557 |
6558 // RegExpKey carries the source and flags of a regular expression as key. | 6558 // RegExpKey carries the source and flags of a regular expression as key. |
6559 class RegExpKey : public HashTableKey { | 6559 class RegExpKey : public HashTableKey { |
6560 public: | 6560 public: |
6561 RegExpKey(String* string, JSRegExp::Flags flags) | 6561 RegExpKey(String* string, JSRegExp::Flags flags) |
6562 : string_(string), | 6562 : string_(string), |
6563 flags_(Smi::FromInt(flags.value())) { } | 6563 flags_(Smi::FromInt(flags.value())) { } |
6564 | 6564 |
| 6565 // Rather than storing the key in the hash table, a pointer to the |
| 6566 // stored value is stored where the key should be. IsMatch then |
| 6567 // compares the search key to the found object, rather than comparing |
| 6568 // a key to a key. |
6565 bool IsMatch(Object* obj) { | 6569 bool IsMatch(Object* obj) { |
6566 FixedArray* val = FixedArray::cast(obj); | 6570 FixedArray* val = FixedArray::cast(obj); |
6567 return string_->Equals(String::cast(val->get(JSRegExp::kSourceIndex))) | 6571 return string_->Equals(String::cast(val->get(JSRegExp::kSourceIndex))) |
6568 && (flags_ == val->get(JSRegExp::kFlagsIndex)); | 6572 && (flags_ == val->get(JSRegExp::kFlagsIndex)); |
6569 } | 6573 } |
6570 | 6574 |
6571 uint32_t Hash() { return RegExpHash(string_, flags_); } | 6575 uint32_t Hash() { return RegExpHash(string_, flags_); } |
6572 | 6576 |
6573 Object* AsObject() { | 6577 Object* AsObject() { |
6574 // Plain hash maps, which is where regexp keys are used, don't | 6578 // Plain hash maps, which is where regexp keys are used, don't |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7214 Object* CompilationCacheTable::PutRegExp(String* src, | 7218 Object* CompilationCacheTable::PutRegExp(String* src, |
7215 JSRegExp::Flags flags, | 7219 JSRegExp::Flags flags, |
7216 FixedArray* value) { | 7220 FixedArray* value) { |
7217 RegExpKey key(src, flags); | 7221 RegExpKey key(src, flags); |
7218 Object* obj = EnsureCapacity(1, &key); | 7222 Object* obj = EnsureCapacity(1, &key); |
7219 if (obj->IsFailure()) return obj; | 7223 if (obj->IsFailure()) return obj; |
7220 | 7224 |
7221 CompilationCacheTable* cache = | 7225 CompilationCacheTable* cache = |
7222 reinterpret_cast<CompilationCacheTable*>(obj); | 7226 reinterpret_cast<CompilationCacheTable*>(obj); |
7223 int entry = cache->FindInsertionEntry(key.Hash()); | 7227 int entry = cache->FindInsertionEntry(key.Hash()); |
| 7228 // We store the value in the key slot, and compare the search key |
| 7229 // to the stored value with a custon IsMatch function during lookups. |
7224 cache->set(EntryToIndex(entry), value); | 7230 cache->set(EntryToIndex(entry), value); |
7225 cache->set(EntryToIndex(entry) + 1, value); | 7231 cache->set(EntryToIndex(entry) + 1, value); |
7226 cache->ElementAdded(); | 7232 cache->ElementAdded(); |
7227 return cache; | 7233 return cache; |
7228 } | 7234 } |
7229 | 7235 |
7230 | 7236 |
7231 // SymbolsKey used for HashTable where key is array of symbols. | 7237 // SymbolsKey used for HashTable where key is array of symbols. |
7232 class SymbolsKey : public HashTableKey { | 7238 class SymbolsKey : public HashTableKey { |
7233 public: | 7239 public: |
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7974 if (break_point_objects()->IsUndefined()) return 0; | 7980 if (break_point_objects()->IsUndefined()) return 0; |
7975 // Single beak point. | 7981 // Single beak point. |
7976 if (!break_point_objects()->IsFixedArray()) return 1; | 7982 if (!break_point_objects()->IsFixedArray()) return 1; |
7977 // Multiple break points. | 7983 // Multiple break points. |
7978 return FixedArray::cast(break_point_objects())->length(); | 7984 return FixedArray::cast(break_point_objects())->length(); |
7979 } | 7985 } |
7980 #endif | 7986 #endif |
7981 | 7987 |
7982 | 7988 |
7983 } } // namespace v8::internal | 7989 } } // namespace v8::internal |
OLD | NEW |