##// END OF EJS Templates
rust-index: optimize find_gca_candidates() on less than 8 revisions...
Georges Racinet -
r52122:1b23aaf5 default
parent child Browse files
Show More
@@ -1053,7 +1053,9 b' impl Index {'
1053
1053
1054 let revisions: Vec<Revision> = as_set.into_iter().collect();
1054 let revisions: Vec<Revision> = as_set.into_iter().collect();
1055
1055
1056 if revisions.len() <= 63 {
1056 if revisions.len() < 8 {
1057 self.find_gca_candidates::<u8>(&revisions)
1058 } else if revisions.len() < 64 {
1057 self.find_gca_candidates::<u64>(&revisions)
1059 self.find_gca_candidates::<u64>(&revisions)
1058 } else {
1060 } else {
1059 self.find_gca_candidates::<NonStaticPoisonableBitSet>(&revisions)
1061 self.find_gca_candidates::<NonStaticPoisonableBitSet>(&revisions)
@@ -1314,6 +1316,7 b' trait PoisonableBitSet: Sized + PartialE'
1314 }
1316 }
1315
1317
1316 const U64_POISON: u64 = 1 << 63;
1318 const U64_POISON: u64 = 1 << 63;
1319 const U8_POISON: u8 = 1 << 7;
1317
1320
1318 impl PoisonableBitSet for u64 {
1321 impl PoisonableBitSet for u64 {
1319 fn vec_of_empty(_sets_size: usize, vec_len: usize) -> Vec<Self> {
1322 fn vec_of_empty(_sets_size: usize, vec_len: usize) -> Vec<Self> {
@@ -1361,6 +1364,52 b' impl PoisonableBitSet for u64 {'
1361 }
1364 }
1362 }
1365 }
1363
1366
1367 impl PoisonableBitSet for u8 {
1368 fn vec_of_empty(_sets_size: usize, vec_len: usize) -> Vec<Self> {
1369 vec![0; vec_len]
1370 }
1371
1372 fn size(&self) -> usize {
1373 1
1374 }
1375
1376 fn capacity(&self) -> usize {
1377 7
1378 }
1379
1380 fn add(&mut self, n: usize) {
1381 (*self) |= 1 << n;
1382 }
1383
1384 fn discard(&mut self, n: usize) {
1385 (*self) &= u8::MAX - (1 << n);
1386 }
1387
1388 fn union(&mut self, other: &Self) {
1389 if *self != *other {
1390 (*self) |= *other;
1391 }
1392 }
1393
1394 fn is_full_range(&self, n: usize) -> bool {
1395 *self + 1 == (1 << n)
1396 }
1397
1398 fn is_empty(&self) -> bool {
1399 *self == 0
1400 }
1401
1402 fn poison(&mut self) {
1403 *self = U8_POISON;
1404 }
1405
1406 fn is_poisoned(&self) -> bool {
1407 // equality comparison would be tempting but would not resist
1408 // operations after poisoning (even if these should be bogus).
1409 *self >= U8_POISON
1410 }
1411 }
1412
1364 /// A poisonable bit set whose capacity is not known at compile time but
1413 /// A poisonable bit set whose capacity is not known at compile time but
1365 /// is constant after initial construction
1414 /// is constant after initial construction
1366 ///
1415 ///
@@ -20,7 +20,10 b' use cpython::{'
20 };
20 };
21 use hg::{
21 use hg::{
22 errors::HgError,
22 errors::HgError,
23 index::{IndexHeader, Phase, RevisionDataParams, SnapshotsCache},
23 index::{
24 IndexHeader, Phase, RevisionDataParams, SnapshotsCache,
25 INDEX_ENTRY_SIZE,
26 },
24 nodemap::{Block, NodeMapError, NodeTree},
27 nodemap::{Block, NodeMapError, NodeTree},
25 revlog::{nodemap::NodeMap, NodePrefix, RevlogError, RevlogIndex},
28 revlog::{nodemap::NodeMap, NodePrefix, RevlogError, RevlogIndex},
26 BaseRevision, Revision, UncheckedRevision, NULL_REVISION,
29 BaseRevision, Revision, UncheckedRevision, NULL_REVISION,
@@ -483,12 +486,26 b' py_class!(pub class MixedIndex |py| {'
483
486
484 @property
487 @property
485 def entry_size(&self) -> PyResult<PyInt> {
488 def entry_size(&self) -> PyResult<PyInt> {
486 self.cindex(py).borrow().inner().getattr(py, "entry_size")?.extract::<PyInt>(py)
489 let rust_res: PyInt = INDEX_ENTRY_SIZE.to_py_object(py);
490
491 let c_res = self.cindex(py).borrow().inner()
492 .getattr(py, "entry_size")?;
493 assert_py_eq(py, "entry_size", rust_res.as_object(), &c_res)?;
494
495 Ok(rust_res)
487 }
496 }
488
497
489 @property
498 @property
490 def rust_ext_compat(&self) -> PyResult<PyInt> {
499 def rust_ext_compat(&self) -> PyResult<PyInt> {
491 self.cindex(py).borrow().inner().getattr(py, "rust_ext_compat")?.extract::<PyInt>(py)
500 // will be entirely removed when the Rust index yet useful to
501 // implement in Rust to detangle things when removing `self.cindex`
502 let rust_res: PyInt = 1.to_py_object(py);
503
504 let c_res = self.cindex(py).borrow().inner()
505 .getattr(py, "rust_ext_compat")?;
506 assert_py_eq(py, "rust_ext_compat", rust_res.as_object(), &c_res)?;
507
508 Ok(rust_res)
492 }
509 }
493
510
494 });
511 });
@@ -671,7 +688,7 b' impl MixedIndex {'
671 let rust_index_len = self.index(py).borrow().len();
688 let rust_index_len = self.index(py).borrow().len();
672 let cindex_len = self.cindex(py).borrow().inner().len(py)?;
689 let cindex_len = self.cindex(py).borrow().inner().len(py)?;
673 assert_eq!(rust_index_len, cindex_len);
690 assert_eq!(rust_index_len, cindex_len);
674 Ok(cindex_len)
691 Ok(rust_index_len)
675 }
692 }
676
693
677 /// This is scaffolding at this point, but it could also become
694 /// This is scaffolding at this point, but it could also become
General Comments 0
You need to be logged in to leave comments. Login now