@@ -298,14 +298,19 @@ impl Object {
298
298
/// to be a `&str` slice and not an owned `String`. The internals of
299
299
/// `Object` will handle the heap allocation of the key if needed for
300
300
/// better performance.
301
+ #[ inline]
301
302
pub fn insert ( & mut self , key : & str , value : JsonValue ) {
303
+ self . insert_index ( key, value) ;
304
+ }
305
+
306
+ pub ( crate ) fn insert_index ( & mut self , key : & str , value : JsonValue ) -> usize {
302
307
let key = key. as_bytes ( ) ;
303
308
let hash = hash_key ( key) ;
304
309
305
310
if self . store . len ( ) == 0 {
306
311
self . store . push ( Node :: new ( value, hash, key. len ( ) ) ) ;
307
312
self . store [ 0 ] . key . attach ( key) ;
308
- return ;
313
+ return 0 ;
309
314
}
310
315
311
316
let mut node = unsafe { & mut * self . node_at_index_mut ( 0 ) } ;
@@ -314,28 +319,38 @@ impl Object {
314
319
loop {
315
320
if hash == node. key . hash && key == node. key . as_bytes ( ) {
316
321
node. value = value;
317
- return ;
322
+ return parent ;
318
323
} else if hash < node. key . hash {
319
324
if node. left != 0 {
320
325
parent = node. left ;
321
326
node = unsafe { & mut * self . node_at_index_mut ( node. left ) } ;
322
327
continue ;
323
328
}
324
- self . store [ parent] . left = self . add_node ( key, value, hash) ;
325
- return ;
329
+ let index = self . add_node ( key, value, hash) ;
330
+ self . store [ parent] . left = index;
331
+
332
+ return index;
326
333
} else {
327
334
if node. right != 0 {
328
335
parent = node. right ;
329
336
node = unsafe { & mut * self . node_at_index_mut ( node. right ) } ;
330
337
continue ;
331
338
}
332
- self . store [ parent] . right = self . add_node ( key, value, hash) ;
333
- return ;
339
+ let index = self . add_node ( key, value, hash) ;
340
+ self . store [ parent] . right = index;
341
+
342
+ return index;
334
343
}
335
344
}
336
345
}
337
346
338
347
#[ inline]
348
+ pub ( crate ) fn override_at ( & mut self , index : usize , value : JsonValue ) {
349
+ self . store [ index] . value = value;
350
+ }
351
+
352
+ #[ inline]
353
+ #[ deprecated( since="0.11.11" , note="Was only meant for internal use" ) ]
339
354
pub fn override_last ( & mut self , value : JsonValue ) {
340
355
if let Some ( node) = self . store . last_mut ( ) {
341
356
node. value = value;
0 commit comments