@@ -44,7 +44,7 @@ impl Index {
44
44
debug ! ( "lookup_item: index={:?} words.len={:?}" ,
45
45
index, words. len( ) ) ;
46
46
47
- let position = u32:: from_be ( words[ index] ) ;
47
+ let position = u32:: from_le ( words[ index] ) ;
48
48
if position == u32:: MAX {
49
49
debug ! ( "lookup_item: position=u32::MAX" ) ;
50
50
None
@@ -61,7 +61,7 @@ impl Index {
61
61
if position == u32:: MAX {
62
62
None
63
63
} else {
64
- Some ( ( DefIndex :: new ( index) , u32:: from_be ( position) ) )
64
+ Some ( ( DefIndex :: new ( index) , u32:: from_le ( position) ) )
65
65
}
66
66
} )
67
67
}
@@ -100,13 +100,11 @@ impl IndexData {
100
100
"recorded position for item {:?} twice, first at {:?} and now at {:?}" ,
101
101
item, self . positions[ item] , position) ;
102
102
103
- self . positions [ item] = position;
103
+ self . positions [ item] = position. to_le ( ) ;
104
104
}
105
105
106
106
pub fn write_index ( & self , buf : & mut Cursor < Vec < u8 > > ) {
107
- for & position in & self . positions {
108
- write_be_u32 ( buf, position) ;
109
- }
107
+ buf. write_all ( words_to_bytes ( & self . positions ) ) . unwrap ( ) ;
110
108
}
111
109
}
112
110
@@ -120,7 +118,7 @@ pub struct DenseIndex {
120
118
impl DenseIndex {
121
119
pub fn lookup ( & self , buf : & [ u8 ] , ix : u32 ) -> Option < u32 > {
122
120
let data = bytes_to_words ( & buf[ self . start ..self . end ] ) ;
123
- data. get ( ix as usize ) . map ( |d| u32:: from_be ( * d) )
121
+ data. get ( ix as usize ) . map ( |d| u32:: from_le ( * d) )
124
122
}
125
123
pub fn from_buf ( buf : & [ u8 ] , start : usize , end : usize ) -> Self {
126
124
assert ! ( ( end-start) %4 == 0 && start <= end && end <= buf. len( ) ) ;
@@ -135,23 +133,16 @@ pub fn write_dense_index(entries: Vec<u32>, buf: &mut Cursor<Vec<u8>>) {
135
133
let elen = entries. len ( ) ;
136
134
assert ! ( elen < u32 :: MAX as usize ) ;
137
135
138
- for entry in entries {
139
- write_be_u32 ( buf, entry) ;
140
- }
136
+ buf. write_all ( words_to_bytes ( & entries) ) . unwrap ( ) ;
141
137
142
138
info ! ( "write_dense_index: {} entries" , elen) ;
143
139
}
144
140
145
- fn write_be_u32 < W : Write > ( w : & mut W , u : u32 ) {
146
- let _ = w. write_all ( & [
147
- ( u >> 24 ) as u8 ,
148
- ( u >> 16 ) as u8 ,
149
- ( u >> 8 ) as u8 ,
150
- ( u >> 0 ) as u8 ,
151
- ] ) ;
152
- }
153
-
154
141
fn bytes_to_words ( b : & [ u8 ] ) -> & [ u32 ] {
155
142
assert ! ( b. len( ) % 4 == 0 ) ;
156
143
unsafe { slice:: from_raw_parts ( b. as_ptr ( ) as * const u32 , b. len ( ) /4 ) }
157
144
}
145
+
146
+ fn words_to_bytes ( w : & [ u32 ] ) -> & [ u8 ] {
147
+ unsafe { slice:: from_raw_parts ( w. as_ptr ( ) as * const u8 , w. len ( ) * 4 ) }
148
+ }
0 commit comments