| OLD | NEW | 
|---|
| 1 // Copyright (c) 2013, the Dart project authors.  Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors.  Please see the AUTHORS file | 
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a | 
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "vm/weak_table.h" | 5 #include "vm/weak_table.h" | 
| 6 | 6 | 
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" | 
| 8 #include "vm/raw_object.h" | 8 #include "vm/raw_object.h" | 
| 9 | 9 | 
| 10 namespace dart { | 10 namespace dart { | 
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 68   set_used(used() + 1); | 68   set_used(used() + 1); | 
| 69   set_count(count() + 1); | 69   set_count(count() + 1); | 
| 70 | 70 | 
| 71   // Rehash if needed to ensure that there are empty slots available. | 71   // Rehash if needed to ensure that there are empty slots available. | 
| 72   if (used_ >= limit()) { | 72   if (used_ >= limit()) { | 
| 73     Rehash(); | 73     Rehash(); | 
| 74   } | 74   } | 
| 75 } | 75 } | 
| 76 | 76 | 
| 77 | 77 | 
|  | 78 void WeakTable::Reset() { | 
|  | 79   intptr_t* old_data = data_; | 
|  | 80   used_ = 0; | 
|  | 81   count_ = 0; | 
|  | 82   size_ = kMinSize; | 
|  | 83   data_ = reinterpret_cast<intptr_t*>(calloc(size_, kEntrySize * kWordSize)); | 
|  | 84   free(old_data); | 
|  | 85 } | 
|  | 86 | 
|  | 87 | 
| 78 void WeakTable::Rehash() { | 88 void WeakTable::Rehash() { | 
| 79   intptr_t old_size = size(); | 89   intptr_t old_size = size(); | 
| 80   intptr_t* old_data = data_; | 90   intptr_t* old_data = data_; | 
| 81 | 91 | 
| 82   intptr_t new_size = SizeFor(count(), size()); | 92   intptr_t new_size = SizeFor(count(), size()); | 
| 83   ASSERT(Utils::IsPowerOfTwo(new_size)); | 93   ASSERT(Utils::IsPowerOfTwo(new_size)); | 
| 84   intptr_t* new_data = reinterpret_cast<intptr_t*>( | 94   intptr_t* new_data = reinterpret_cast<intptr_t*>( | 
| 85       calloc(new_size, kEntrySize * kWordSize)); | 95       calloc(new_size, kEntrySize * kWordSize)); | 
| 86 | 96 | 
| 87   intptr_t mask = new_size - 1; | 97   intptr_t mask = new_size - 1; | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
| 106   // We should only have used valid entries. | 116   // We should only have used valid entries. | 
| 107   ASSERT(used() == count()); | 117   ASSERT(used() == count()); | 
| 108 | 118 | 
| 109   // Switch to using the newly allocated backing store. | 119   // Switch to using the newly allocated backing store. | 
| 110   size_ = new_size; | 120   size_ = new_size; | 
| 111   data_ = new_data; | 121   data_ = new_data; | 
| 112   free(old_data); | 122   free(old_data); | 
| 113 } | 123 } | 
| 114 | 124 | 
| 115 }  // namespace dart | 125 }  // namespace dart | 
| OLD | NEW | 
|---|