Chromium Code Reviews| Index: src/objects.cc |
| =================================================================== |
| --- src/objects.cc (revision 338) |
| +++ src/objects.cc (working copy) |
| @@ -2379,9 +2379,15 @@ |
| // First check whether we can update existing code cache without |
| // extending it. |
| int length = cache->length(); |
| + int deleted_index = -1; |
| for (int i = 0; i < length; i += 2) { |
| Object* key = cache->get(i); |
| + if (key->IsNull()) { |
| + if (deleted_index < 0) deleted_index = i; |
| + continue; |
| + } |
| if (key->IsUndefined()) { |
| + if (deleted_index > 0) i = deleted_index; |
|
Kasper Lund
2008/09/18 10:56:22
What if deleted_index is 0? Shouldn't you use that
|
| cache->set(i + 0, name); |
| cache->set(i + 1, code); |
| return this; |
| @@ -2395,6 +2401,14 @@ |
| } |
| } |
| + // Reached the end of the code cache. If there were deleted |
| + // elements, reuse the space for the first of them. |
| + if (deleted_index > 0) { |
|
Kasper Lund
2008/09/18 10:56:22
How about reusing if deleted_index is 0? Isn't tha
|
| + cache->set(deleted_index + 0, name); |
| + cache->set(deleted_index + 1, code); |
| + return this; |
| + } |
| + |
| // Extend the code cache with some new entries (at least one). |
| int new_length = length + ((length >> 1) & ~1) + 2; |
| ASSERT((new_length & 1) == 0); // must be a multiple of two |
| @@ -2415,6 +2429,9 @@ |
| int length = cache->length(); |
| for (int i = 0; i < length; i += 2) { |
| Object* key = cache->get(i); |
| + if (key->IsNull()) { |
|
Kasper Lund
2008/09/18 10:56:22
Maybe add a comment here that explains that we're
|
| + continue; |
| + } |
| if (key->IsUndefined()) { |
| return key; |
| } |
| @@ -2440,8 +2457,8 @@ |
| void Map::RemoveFromCodeCache(int index) { |
| FixedArray* array = code_cache(); |
| ASSERT(array->length() >= index && array->get(index)->IsCode()); |
| - array->set_undefined(index - 1); // key |
| - array->set_undefined(index); // code |
| + array->set_null(index - 1); // key |
|
Kasper Lund
2008/09/18 10:56:22
Add comment that explains that deleted entries are
|
| + array->set_null(index); // code |
| } |