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

Side by Side Diff: runtime/vm/weak_table.cc

Issue 1399783002: Add a hash map for a raw object to id mapping, this table will be used during snapshot writing in o… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: code-review-comments Created 5 years, 2 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 unified diff | Download patch
« no previous file with comments | « runtime/vm/weak_table.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « runtime/vm/weak_table.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698