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

Unified Diff: src/objects.cc

Issue 457: Added a EvalCache that caches eval'ed scripts and compiled function boilerpla... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years, 3 months 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 side-by-side diff with in-line comments
Download patch
Index: src/objects.cc
===================================================================
--- src/objects.cc (revision 147)
+++ src/objects.cc (working copy)
@@ -5233,7 +5233,7 @@
// The NumberKey uses carries the uint32_t as key.
// This avoids allocation in HasProperty.
-class Dictionary::NumberKey : public Dictionary::Key {
+class NumberKey : public HashTableKey {
public:
explicit NumberKey(uint32_t number) {
number_ = number;
@@ -5279,14 +5279,14 @@
uint32_t number_;
};
+
// StringKey simply carries a string object as key.
-class Dictionary::StringKey : public Dictionary::Key {
+class StringKey : public HashTableKey {
public:
explicit StringKey(String* string) {
string_ = string;
}
- private:
bool IsMatch(Object* other) {
if (!other->IsString()) return false;
return string_->Equals(String::cast(other));
@@ -5307,10 +5307,10 @@
String* string_;
};
-// Utf8Key carries a vector of chars as key.
-class SymbolTable::Utf8Key : public SymbolTable::Key {
+// Utf8SymbolKey carries a vector of chars as key.
+class Utf8SymbolKey : public HashTableKey {
public:
- explicit Utf8Key(Vector<const char> string)
+ explicit Utf8SymbolKey(Vector<const char> string)
: string_(string), hash_(0) { }
bool IsMatch(Object* other) {
@@ -5350,10 +5350,10 @@
};
-// StringKey carries a string object as key.
-class SymbolTable::StringKey : public SymbolTable::Key {
+// SymbolKey carries a string/symbol object as key.
+class SymbolKey : public HashTableKey {
public:
- explicit StringKey(String* string) : string_(string) { }
+ explicit SymbolKey(String* string) : string_(string) { }
HashFunction GetHashFunction() {
return StringHash;
@@ -5417,7 +5417,7 @@
// Find entry for key otherwise return -1.
template <int prefix_size, int element_size>
-int HashTable<prefix_size, element_size>::FindEntry(Key* key) {
+int HashTable<prefix_size, element_size>::FindEntry(HashTableKey* key) {
uint32_t nof = NumberOfElements();
if (nof == 0) return -1; // Bail out if empty.
@@ -5444,7 +5444,8 @@
template<int prefix_size, int element_size>
-Object* HashTable<prefix_size, element_size>::EnsureCapacity(int n, Key* key) {
+Object* HashTable<prefix_size, element_size>::EnsureCapacity(
+ int n, HashTableKey* key) {
int capacity = Capacity();
int nof = NumberOfElements() + n;
// Make sure 20% is free
@@ -5502,19 +5503,23 @@
template class HashTable<2, 3>;
+// Force instantiation of EvalCache's base class
+template class HashTable<0, 2>;
+
+
Object* SymbolTable::LookupString(String* string, Object** s) {
- StringKey key(string);
+ SymbolKey key(string);
return LookupKey(&key, s);
}
Object* SymbolTable::LookupSymbol(Vector<const char> str, Object** s) {
- Utf8Key key(str);
+ Utf8SymbolKey key(str);
return LookupKey(&key, s);
}
-Object* SymbolTable::LookupKey(Key* key, Object** s) {
+Object* SymbolTable::LookupKey(HashTableKey* key, Object** s) {
int entry = FindEntry(key);
// Symbol already in table.
@@ -5545,6 +5550,31 @@
}
+Object* EvalCache::Lookup(String* src) {
+ StringKey key(src);
+ int entry = FindEntry(&key);
+ if (entry != -1) {
+ return get(EntryToIndex(entry) + 1);
+ } else {
+ return Heap::undefined_value();
+ }
+}
+
+
+Object* EvalCache::Put(String* src, Object* value) {
+ StringKey key(src);
+ Object* obj = EnsureCapacity(1, &key);
+ if (obj->IsFailure()) return obj;
+
+ EvalCache* cache = reinterpret_cast<EvalCache*>(obj);
+ int entry = cache->FindInsertionEntry(src, key.Hash());
+ cache->set(EntryToIndex(entry), src);
+ cache->set(EntryToIndex(entry) + 1, value);
+ cache->ElementAdded();
+ return cache;
+}
+
+
Object* Dictionary::Allocate(int at_least_space_for) {
Object* obj = DictionaryBase::Allocate(at_least_space_for);
// Initialize the next enumeration index.
@@ -5607,7 +5637,7 @@
}
-Object* Dictionary::EnsureCapacity(int n, Key* key) {
+Object* Dictionary::EnsureCapacity(int n, HashTableKey* key) {
// Check whether there are enough enumeration indices to add n elements.
if (key->IsStringKey() &&
!PropertyDetails::IsValidIndex(NextEnumerationIndex() + n)) {
@@ -5663,7 +5693,7 @@
}
-Object* Dictionary::AtPut(Key* key, Object* value) {
+Object* Dictionary::AtPut(HashTableKey* key, Object* value) {
int entry = FindEntry(key);
// If the entry is present set the value;
@@ -5683,7 +5713,8 @@
}
-Object* Dictionary::Add(Key* key, Object* value, PropertyDetails details) {
+Object* Dictionary::Add(HashTableKey* key, Object* value,
+ PropertyDetails details) {
// Check whether the dictionary should be extended.
Object* obj = EnsureCapacity(1, key);
if (obj->IsFailure()) return obj;

Powered by Google App Engine
This is Rietveld 408576698