Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Side by Side Diff: src/objects.cc

Issue 8104: Regexp caching (Closed)
Patch Set: Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 5533 matching lines...) Expand 10 before | Expand all | Expand 10 after
5544 5544
5545 static uint32_t StringHash(Object* obj) { 5545 static uint32_t StringHash(Object* obj) {
5546 return String::cast(obj)->Hash(); 5546 return String::cast(obj)->Hash();
5547 } 5547 }
5548 5548
5549 bool IsStringKey() { return true; } 5549 bool IsStringKey() { return true; }
5550 5550
5551 String* string_; 5551 String* string_;
5552 }; 5552 };
5553 5553
5554 // RegExpKey carries a regexp object as key.
Kasper Lund 2008/10/24 06:42:50 Is this really so? It seems to hold a string and s
5555 class RegExpKey : public HashTableKey {
5556 public:
5557 RegExpKey(String* string, int flags)
5558 : string_(string),
5559 flags_(Smi::FromInt(flags)) { }
5560
5561 bool IsMatch(Object* obj) {
5562 FixedArray* val = FixedArray::cast(obj);
5563 return string_->Equals(String::cast(val->get(JSRegExp::kSourceIndex)))
5564 && (flags_ == val->get(JSRegExp::kFlagsIndex));
5565 }
5566
5567 uint32_t Hash() { return RegExpHash(string_, flags_); }
5568
5569 HashFunction GetHashFunction() { return RegExpObjHash; }
5570
5571 Object* GetObject() {
5572 // Plain hash maps, which is where regexp keys are used, don't
5573 // use this function.
5574 UNREACHABLE();
5575 return NULL;
5576 }
5577
5578 static uint32_t RegExpObjHash(Object* obj) {
Kasper Lund 2008/10/24 06:42:50 I don't like the Obj abbreviation here. RegExpObje
5579 FixedArray* val = FixedArray::cast(obj);
5580 return RegExpHash(String::cast(val->get(JSRegExp::kSourceIndex)),
5581 Smi::cast(val->get(JSRegExp::kFlagsIndex)));
5582 }
5583
5584 static uint32_t RegExpHash(String* string, Smi* flags) {
5585 return string->Hash() + flags->value();
5586 }
5587
5588 bool IsStringKey() { return false; }
5589
5590 String* string_;
5591 Smi* flags_;
5592 };
5593
5554 // Utf8SymbolKey carries a vector of chars as key. 5594 // Utf8SymbolKey carries a vector of chars as key.
5555 class Utf8SymbolKey : public HashTableKey { 5595 class Utf8SymbolKey : public HashTableKey {
5556 public: 5596 public:
5557 explicit Utf8SymbolKey(Vector<const char> string) 5597 explicit Utf8SymbolKey(Vector<const char> string)
5558 : string_(string), length_field_(0) { } 5598 : string_(string), length_field_(0) { }
5559 5599
5560 bool IsMatch(Object* string) { 5600 bool IsMatch(Object* string) {
5561 return String::cast(string)->IsEqualTo(string_); 5601 return String::cast(string)->IsEqualTo(string_);
5562 } 5602 }
5563 5603
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
5818 5858
5819 5859
5820 Object* CompilationCacheTable::Lookup(String* src) { 5860 Object* CompilationCacheTable::Lookup(String* src) {
5821 StringKey key(src); 5861 StringKey key(src);
5822 int entry = FindEntry(&key); 5862 int entry = FindEntry(&key);
5823 if (entry == -1) return Heap::undefined_value(); 5863 if (entry == -1) return Heap::undefined_value();
5824 return get(EntryToIndex(entry) + 1); 5864 return get(EntryToIndex(entry) + 1);
5825 } 5865 }
5826 5866
5827 5867
5868 Object* CompilationCacheTable::LookupRegExp(String* source, int flags) {
5869 RegExpKey key(source, flags);
5870 int entry = FindEntry(&key);
5871 if (entry == -1) return Heap::undefined_value();
5872 return get(EntryToIndex(entry) + 1);
5873 }
5874
5875
5828 Object* CompilationCacheTable::Put(String* src, Object* value) { 5876 Object* CompilationCacheTable::Put(String* src, Object* value) {
5829 StringKey key(src); 5877 StringKey key(src);
5830 Object* obj = EnsureCapacity(1, &key); 5878 Object* obj = EnsureCapacity(1, &key);
5831 if (obj->IsFailure()) return obj; 5879 if (obj->IsFailure()) return obj;
5832 5880
5833 CompilationCacheTable* cache = 5881 CompilationCacheTable* cache =
5834 reinterpret_cast<CompilationCacheTable*>(obj); 5882 reinterpret_cast<CompilationCacheTable*>(obj);
5835 int entry = cache->FindInsertionEntry(src, key.Hash()); 5883 int entry = cache->FindInsertionEntry(src, key.Hash());
5836 cache->set(EntryToIndex(entry), src); 5884 cache->set(EntryToIndex(entry), src);
5837 cache->set(EntryToIndex(entry) + 1, value); 5885 cache->set(EntryToIndex(entry) + 1, value);
5838 cache->ElementAdded(); 5886 cache->ElementAdded();
5839 return cache; 5887 return cache;
5840 } 5888 }
5841 5889
5842 5890
5891 Object* CompilationCacheTable::PutRegExp(String* src,
5892 int flags,
5893 FixedArray* value) {
5894 RegExpKey key(src, flags);
5895 Object* obj = EnsureCapacity(1, &key);
5896 if (obj->IsFailure()) return obj;
5897
5898 CompilationCacheTable* cache =
5899 reinterpret_cast<CompilationCacheTable*>(obj);
5900 int entry = cache->FindInsertionEntry(value, key.Hash());
5901 cache->set(EntryToIndex(entry), value);
5902 cache->set(EntryToIndex(entry) + 1, value);
5903 cache->ElementAdded();
5904 return cache;
5905 }
5906
5907
5843 // SymbolsKey used for HashTable where key is array of symbols. 5908 // SymbolsKey used for HashTable where key is array of symbols.
5844 class SymbolsKey : public HashTableKey { 5909 class SymbolsKey : public HashTableKey {
5845 public: 5910 public:
5846 explicit SymbolsKey(FixedArray* symbols) : symbols_(symbols) { } 5911 explicit SymbolsKey(FixedArray* symbols) : symbols_(symbols) { }
5847 5912
5848 bool IsMatch(Object* symbols) { 5913 bool IsMatch(Object* symbols) {
5849 FixedArray* o = FixedArray::cast(symbols); 5914 FixedArray* o = FixedArray::cast(symbols);
5850 int len = symbols_->length(); 5915 int len = symbols_->length();
5851 if (o->length() != len) return false; 5916 if (o->length() != len) return false;
5852 for (int i = 0; i < len; i++) { 5917 for (int i = 0; i < len; i++) {
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
6648 // No break point. 6713 // No break point.
6649 if (break_point_objects()->IsUndefined()) return 0; 6714 if (break_point_objects()->IsUndefined()) return 0;
6650 // Single beak point. 6715 // Single beak point.
6651 if (!break_point_objects()->IsFixedArray()) return 1; 6716 if (!break_point_objects()->IsFixedArray()) return 1;
6652 // Multiple break points. 6717 // Multiple break points.
6653 return FixedArray::cast(break_point_objects())->length(); 6718 return FixedArray::cast(break_point_objects())->length();
6654 } 6719 }
6655 6720
6656 6721
6657 } } // namespace v8::internal 6722 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698