MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / add

Method add

aiscript-arena/src/dynamic_roots.rs:249–286  ·  view source on GitHub ↗
(&mut self, p: Gc<'gc, ()>)

Source from the content-addressed store, hash-verified

247 }
248
249 fn add(&mut self, p: Gc<'gc, ()>) -> Index {
250 // Occupied slot refcount starts at 0. A refcount of 0 and a set ptr implies that there is
251 // *one* live reference.
252
253 if self.next_free != NULL_INDEX {
254 let idx = self.next_free;
255 let slot = &mut self.slots[idx];
256 match *slot {
257 Slot::Vacant { next_free } => {
258 self.next_free = next_free;
259 }
260 Slot::Occupied { .. } => panic!("free slot linked list corrupted"),
261 }
262 *slot = Slot::Occupied {
263 root: p,
264 ref_count: 0,
265 };
266 idx
267 } else {
268 let idx = self.slots.len();
269
270 let old_capacity = self.slots.capacity();
271 self.slots.push(Slot::Occupied {
272 root: p,
273 ref_count: 0,
274 });
275 let new_capacity = self.slots.capacity();
276
277 debug_assert!(new_capacity >= old_capacity);
278 if new_capacity > old_capacity {
279 self.metrics.mark_external_allocation(
280 (new_capacity - old_capacity) * mem::size_of::<Slot>(),
281 );
282 }
283
284 idx
285 }
286 }
287
288 fn inc(&mut self, idx: Index) {
289 match &mut self.slots[idx] {

Callers 1

stashMethod · 0.45

Calls 3

lenMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected