Skip to content

Commit 4cb68b6

Browse files
Keatsboydgreenfield
authored andcommitted
Remove backward_bytes feature
1 parent a7243fb commit 4cb68b6

File tree

2 files changed

+13
-53
lines changed

2 files changed

+13
-53
lines changed

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ memmap = "0.7.0"
1010
murmurhash3 = "0.0.5"
1111
once_cell = "1.3.1"
1212

13-
[features]
14-
backward_bytes = []
15-
1613
[dev-dependencies]
1714
criterion = "0.3"
1815

src/mmap_bitvec.rs

Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl MmapBitVec {
244244
// `shift` is the same as the position of the last bit
245245
let shift = (r.end & 7) as u8;
246246
for (new_idx, old_idx) in (byte_idx_st..=byte_idx_en).enumerate() {
247-
let old_val = unsafe { order_byte(*ptr.add(old_idx)) };
247+
let old_val = unsafe { *ptr.add(old_idx) };
248248
if new_idx > 0 {
249249
if let Some(shifted_val) = old_val.checked_shr(u32::from(shift)) {
250250
v[new_idx - 1] |= shifted_val;
@@ -295,12 +295,12 @@ impl MmapBitVec {
295295
let shifted_val = val.checked_shr(u32::from(8 - shift)).unwrap_or(0);
296296
if idx > 0 && shift != 8 {
297297
unsafe {
298-
*mmap.offset(idx as isize - 1) |= order_byte(shifted_val);
298+
*mmap.offset(idx as isize - 1) |= shifted_val;
299299
}
300300
}
301301
let shifted_val = (val & mask).checked_shl(u32::from(shift)).unwrap_or(*val);
302302
unsafe {
303-
*mmap.add(idx) |= order_byte(shifted_val);
303+
*mmap.add(idx) |= shifted_val;
304304
}
305305
}
306306
}
@@ -317,10 +317,7 @@ impl BitVector for MmapBitVec {
317317
panic!("Invalid bit vector index");
318318
}
319319
let byte_idx = (i >> 3) as isize;
320-
#[cfg(not(feature = "backward_bytes"))]
321320
let bit_idx = 7 - (i & 7) as u8;
322-
#[cfg(feature = "backward_bytes")]
323-
let bit_idx = (i & 7) as u8;
324321

325322
let mmap: *const u8 = self.mmap.as_ptr();
326323
unsafe { (*mmap.offset(byte_idx) & (1 << bit_idx)) != 0 }
@@ -336,10 +333,7 @@ impl BitVector for MmapBitVec {
336333
panic!("Invalid bit vector index");
337334
}
338335
let byte_idx = (i >> 3) as isize;
339-
#[cfg(not(feature = "backward_bytes"))]
340336
let bit_idx = 7 - (i & 7) as u8;
341-
#[cfg(feature = "backward_bytes")]
342-
let bit_idx = (i & 7) as u8;
343337

344338
let mmap: *mut u8 = self.mmap.as_mut_ptr();
345339
unsafe {
@@ -368,7 +362,7 @@ impl BitVector for MmapBitVec {
368362
size_front = 0;
369363
}
370364
if let Some(mask) = 0xFFu8.checked_shl(u32::from(size_front)) {
371-
let byte = unsafe { *mmap.add(byte_idx_st) & order_byte(mask) };
365+
let byte = unsafe { *mmap.add(byte_idx_st) & mask };
372366
bit_count += byte.count_ones() as usize
373367
}
374368

@@ -383,7 +377,7 @@ impl BitVector for MmapBitVec {
383377
size_back = 0;
384378
}
385379
if let Some(mask) = 0xFFu8.checked_shr(u32::from(size_back)) {
386-
let byte = unsafe { *mmap.add(byte_idx_en) & order_byte(mask) };
380+
let byte = unsafe { *mmap.add(byte_idx_en) & mask };
387381
bit_count += byte.count_ones() as usize
388382
}
389383

@@ -453,12 +447,12 @@ impl BitVector for MmapBitVec {
453447

454448
// read the last byte first
455449
unsafe {
456-
v = u128::from(order_byte(*ptr.add(byte_idx_en)));
450+
v = u128::from(*ptr.add(byte_idx_en));
457451
}
458452
// align the end of the data with the end of the u128
459453
v >>= 7 - ((r.end - 1) & 7);
460454

461-
if r.start < self.size - 128usize && cfg!(not(feature = "backward_bytes")) {
455+
if r.start < self.size - 128usize {
462456
// really nasty/unsafe, but we're just reading a u64/u128 out instead of doing it
463457
// byte-wise --- also does not work with legacy mode!!!
464458
unsafe {
@@ -472,8 +466,7 @@ impl BitVector for MmapBitVec {
472466
let bit_offset = new_size + (r.start & 7) as u8;
473467
for (new_idx, old_idx) in (byte_idx_st..byte_idx_en).enumerate() {
474468
unsafe {
475-
v |= u128::from(order_byte(*ptr.add(old_idx)))
476-
<< (bit_offset - 8u8 * (new_idx as u8 + 1));
469+
v |= u128::from(*ptr.add(old_idx)) << (bit_offset - 8u8 * (new_idx as u8 + 1));
477470
}
478471
}
479472
}
@@ -511,7 +504,7 @@ impl BitVector for MmapBitVec {
511504
// new value get masked over the existing 1's
512505
let mmap: *mut u8 = self.mmap.as_mut_ptr();
513506
unsafe {
514-
*mmap.add(byte_idx_st) |= order_byte(front_byte);
507+
*mmap.add(byte_idx_st) |= front_byte;
515508
}
516509

517510
// if the front is all there is, we can bail now
@@ -526,7 +519,7 @@ impl BitVector for MmapBitVec {
526519
}
527520
let back_byte = (x << (128 - size_back) >> 120) as u8;
528521
unsafe {
529-
*mmap.add(byte_idx_en) |= order_byte(back_byte);
522+
*mmap.add(byte_idx_en) |= back_byte;
530523
}
531524

532525
// only two bytes long, bail out
@@ -546,7 +539,7 @@ impl BitVector for MmapBitVec {
546539
}
547540
for (byte_idx, byte) in ((byte_idx_st + 1)..byte_idx_en).zip(bytes.iter()) {
548541
unsafe {
549-
*mmap.add(byte_idx) |= order_byte(*byte);
542+
*mmap.add(byte_idx) |= *byte;
550543
}
551544
}
552545
}
@@ -565,7 +558,7 @@ impl BitVector for MmapBitVec {
565558
let size_front = 8u8 - (r.start & 7) as u8;
566559
if let Some(mask) = 0xFFu8.checked_shl(u32::from(size_front)) {
567560
unsafe {
568-
*mmap.add(byte_idx_st) &= order_byte(mask);
561+
*mmap.add(byte_idx_st) &= mask;
569562
}
570563
}
571564

@@ -581,7 +574,7 @@ impl BitVector for MmapBitVec {
581574
}
582575
if let Some(mask) = 0xFFu8.checked_shr(u32::from(size_back)) {
583576
unsafe {
584-
*mmap.add(byte_idx_en) &= order_byte(mask);
577+
*mmap.add(byte_idx_en) &= mask;
585578
}
586579
}
587580

@@ -607,36 +600,6 @@ impl Drop for MmapBitVec {
607600
}
608601
}
609602

610-
#[inline]
611-
#[cfg(not(feature = "backward_bytes"))]
612-
fn order_byte(b: u8) -> u8 {
613-
b
614-
}
615-
616-
#[inline]
617-
#[cfg(feature = "backward_bytes")]
618-
fn order_byte(b: u8) -> u8 {
619-
// in python: ','.join(str(eval('{:08b}b0'.format(i)[::-1])) for i in range(256))
620-
#[rustfmt::skip]
621-
const BACKWARDS: [u8; 256] = [
622-
0,128,64,192,32,160,96,224,16,144,80,208,48,176,112,240,8,136,72,
623-
200,40,168,104,232,24,152,88,216,56,184,120,248,4,132,68,196,36,
624-
164,100,228,20,148,84,212,52,180,116,244,12,140,76,204,44,172,108,
625-
236,28,156,92,220,60,188,124,252,2,130,66,194,34,162,98,226,18,146,
626-
82,210,50,178,114,242,10,138,74,202,42,170,106,234,26,154,90,218,58,
627-
186,122,250,6,134,70,198,38,166,102,230,22,150,86,214,54,182,118,246,
628-
14,142,78,206,46,174,110,238,30,158,94,222,62,190,126,254,1,129,65,
629-
193,33,161,97,225,17,145,81,209,49,177,113,241,9,137,73,201,41,169,
630-
105,233,25,153,89,217,57,185,121,249,5,133,69,197,37,165,101,229,21,
631-
149,85,213,53,181,117,245,13,141,77,205,45,173,109,237,29,157,93,221,
632-
61,189,125,253,3,131,67,195,35,163,99,227,19,147,83,211,51,179,115,
633-
243,11,139,75,203,43,171,107,235,27,155,91,219,59,187,123,251,7,135,
634-
71,199,39,167,103,231,23,151,87,215,55,183,119,247,15,143,79,207,47,
635-
175,111,239,31,159,95,223,63,191,127,255
636-
];
637-
BACKWARDS[b as usize]
638-
}
639-
640603
#[cfg(test)]
641604
mod test {
642605
use std::path::Path;

0 commit comments

Comments
 (0)