equal
deleted
inserted
replaced
155 public void put(long id, T object) { |
155 public void put(long id, T object) { |
156 if (keys == EMPTY_KEYS) { |
156 if (keys == EMPTY_KEYS) { |
157 // Lazy initialization |
157 // Lazy initialization |
158 initialize(DEFAULT_SIZE); |
158 initialize(DEFAULT_SIZE); |
159 } |
159 } |
160 if (count > 3 * keys.length / 4) { |
|
161 expand(2 * keys.length); |
|
162 } |
|
163 if (object == null) { |
160 if (object == null) { |
164 object = (T) NULL_OBJECT; |
161 object = (T) NULL_OBJECT; |
165 } |
162 } |
166 |
163 |
167 int index = index(id); |
164 int index = index(id); |
169 while (true) { |
166 while (true) { |
170 if (objects[index] == null) { |
167 if (objects[index] == null) { |
171 keys[index] = id; |
168 keys[index] = id; |
172 objects[index] = object; |
169 objects[index] = object; |
173 count++; |
170 count++; |
|
171 // Don't expand lazy since it |
|
172 // can cause resize when replacing |
|
173 // an object. |
|
174 if (count > 3 * keys.length / 4) { |
|
175 expand(2 * keys.length); |
|
176 } |
174 return; |
177 return; |
175 } |
178 } |
176 // if it already exists, replace |
179 // if it already exists, replace |
177 if (keys[index] == id) { |
180 if (keys[index] == id) { |
178 objects[index] = object; |
181 objects[index] = object; |