MCPcopy Index your code
hub / github.com/RustPython/RustPython / get_hint

Method get_hint

crates/vm/src/dict_inner.rs:360–382  ·  view source on GitHub ↗

Fast path lookup using a cached entry index (`hint`). Returns `None` if the hint is stale or the key no longer matches.

(
        &self,
        vm: &VirtualMachine,
        key: &K,
        hint: usize,
    )

Source from the content-addressed store, hash-verified

358 ///
359 /// Returns `None` if the hint is stale or the key no longer matches.
360 pub fn get_hint<K: DictKey + ?Sized>(
361 &self,
362 vm: &VirtualMachine,
363 key: &K,
364 hint: usize,
365 ) -> PyResult<Option<T>> {
366 let (entry_key, entry_value) = {
367 let inner = self.read();
368 let Some(Some(entry)) = inner.entries.get(hint) else {
369 return Ok(None);
370 };
371 if key.key_is(&entry.key) {
372 return Ok(Some(entry.value.clone()));
373 }
374 (entry.key.clone(), entry.value.clone())
375 };
376 // key_eq may run Python __eq__, so must be outside the lock.
377 if key.key_eq(vm, &entry_key)? {
378 Ok(Some(entry_value))
379 } else {
380 Ok(None)
381 }
382 }
383
384 fn _get_inner<K: DictKey + ?Sized>(
385 &self,

Callers 1

get_item_opt_hintMethod · 0.80

Calls 6

key_isMethod · 0.80
key_eqMethod · 0.80
SomeClass · 0.50
readMethod · 0.45
getMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected