Mercurial > hg
comparison rust/hg-cpython/src/dirstate/dirstate_map.rs @ 42888:67853749961b
rust-cpython: replace dyn Iterator<..> of mapping with concrete type
See the previous commit for why. The docstring is moved accordingly.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 08 Sep 2019 12:23:18 +0900 |
parents | 64e28b891796 |
children | ea91a126c803 |
comparison
equal
deleted
inserted
replaced
42887:706104dcb2c8 | 42888:67853749961b |
---|---|
23 dirstate::{decapsule_make_dirstate_tuple, dirs_multiset::Dirs}, | 23 dirstate::{decapsule_make_dirstate_tuple, dirs_multiset::Dirs}, |
24 ref_sharing::{PySharedRefCell, PySharedState}, | 24 ref_sharing::{PySharedRefCell, PySharedState}, |
25 }; | 25 }; |
26 use hg::{ | 26 use hg::{ |
27 DirsMultiset, DirstateEntry, DirstateMap as RustDirstateMap, | 27 DirsMultiset, DirstateEntry, DirstateMap as RustDirstateMap, |
28 DirstateParents, DirstateParseError, EntryState, PARENT_SIZE, | 28 DirstateParents, DirstateParseError, EntryState, StateMapIter, |
29 PARENT_SIZE, | |
29 }; | 30 }; |
30 | 31 |
31 // TODO | 32 // TODO |
32 // This object needs to share references to multiple members of its Rust | 33 // This object needs to share references to multiple members of its Rust |
33 // inner struct, namely `copy_map`, `dirs` and `all_dirs`. | 34 // inner struct, namely `copy_map`, `dirs` and `all_dirs`. |
321 def keys(&self) -> PyResult<DirstateMapKeysIterator> { | 322 def keys(&self) -> PyResult<DirstateMapKeysIterator> { |
322 let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? }; | 323 let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? }; |
323 DirstateMapKeysIterator::from_inner( | 324 DirstateMapKeysIterator::from_inner( |
324 py, | 325 py, |
325 Some(leak_handle), | 326 Some(leak_handle), |
326 Box::new(leaked_ref.iter()), | 327 leaked_ref.iter(), |
327 ) | 328 ) |
328 } | 329 } |
329 | 330 |
330 def items(&self) -> PyResult<DirstateMapItemsIterator> { | 331 def items(&self) -> PyResult<DirstateMapItemsIterator> { |
331 let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? }; | 332 let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? }; |
332 DirstateMapItemsIterator::from_inner( | 333 DirstateMapItemsIterator::from_inner( |
333 py, | 334 py, |
334 Some(leak_handle), | 335 Some(leak_handle), |
335 Box::new(leaked_ref.iter()), | 336 leaked_ref.iter(), |
336 ) | 337 ) |
337 } | 338 } |
338 | 339 |
339 def __iter__(&self) -> PyResult<DirstateMapKeysIterator> { | 340 def __iter__(&self) -> PyResult<DirstateMapKeysIterator> { |
340 let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? }; | 341 let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? }; |
341 DirstateMapKeysIterator::from_inner( | 342 DirstateMapKeysIterator::from_inner( |
342 py, | 343 py, |
343 Some(leak_handle), | 344 Some(leak_handle), |
344 Box::new(leaked_ref.iter()), | 345 leaked_ref.iter(), |
345 ) | 346 ) |
346 } | 347 } |
347 | 348 |
348 def getdirs(&self) -> PyResult<Dirs> { | 349 def getdirs(&self) -> PyResult<Dirs> { |
349 // TODO don't copy, share the reference | 350 // TODO don't copy, share the reference |
436 def copymapiter(&self) -> PyResult<CopyMapKeysIterator> { | 437 def copymapiter(&self) -> PyResult<CopyMapKeysIterator> { |
437 let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? }; | 438 let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? }; |
438 CopyMapKeysIterator::from_inner( | 439 CopyMapKeysIterator::from_inner( |
439 py, | 440 py, |
440 Some(leak_handle), | 441 Some(leak_handle), |
441 Box::new(leaked_ref.copy_map.iter()), | 442 leaked_ref.copy_map.iter(), |
442 ) | 443 ) |
443 } | 444 } |
444 | 445 |
445 def copymapitemsiter(&self) -> PyResult<CopyMapItemsIterator> { | 446 def copymapitemsiter(&self) -> PyResult<CopyMapItemsIterator> { |
446 let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? }; | 447 let (leak_handle, leaked_ref) = unsafe { self.leak_immutable(py)? }; |
447 CopyMapItemsIterator::from_inner( | 448 CopyMapItemsIterator::from_inner( |
448 py, | 449 py, |
449 Some(leak_handle), | 450 Some(leak_handle), |
450 Box::new(leaked_ref.copy_map.iter()), | 451 leaked_ref.copy_map.iter(), |
451 ) | 452 ) |
452 } | 453 } |
453 | 454 |
454 }); | 455 }); |
455 | 456 |
481 } | 482 } |
482 } | 483 } |
483 | 484 |
484 py_shared_ref!(DirstateMap, RustDirstateMap, inner, DirstateMapLeakedRef,); | 485 py_shared_ref!(DirstateMap, RustDirstateMap, inner, DirstateMapLeakedRef,); |
485 | 486 |
486 py_shared_mapping_iterator!( | 487 py_shared_iterator_impl!( |
487 DirstateMapKeysIterator, | 488 DirstateMapKeysIterator, |
488 DirstateMapLeakedRef, | 489 DirstateMapLeakedRef, |
489 Vec<u8>, | 490 StateMapIter<'static>, |
490 DirstateEntry, | |
491 DirstateMap::translate_key, | 491 DirstateMap::translate_key, |
492 Option<PyBytes> | 492 Option<PyBytes> |
493 ); | 493 ); |
494 | 494 |
495 py_shared_mapping_iterator!( | 495 py_shared_iterator_impl!( |
496 DirstateMapItemsIterator, | 496 DirstateMapItemsIterator, |
497 DirstateMapLeakedRef, | 497 DirstateMapLeakedRef, |
498 Vec<u8>, | 498 StateMapIter<'static>, |
499 DirstateEntry, | |
500 DirstateMap::translate_key_value, | 499 DirstateMap::translate_key_value, |
501 Option<(PyBytes, PyObject)> | 500 Option<(PyBytes, PyObject)> |
502 ); | 501 ); |
503 | 502 |
504 fn extract_node_id(py: Python, obj: &PyObject) -> PyResult<[u8; PARENT_SIZE]> { | 503 fn extract_node_id(py: Python, obj: &PyObject) -> PyResult<[u8; PARENT_SIZE]> { |