File tree Expand file tree Collapse file tree 2 files changed +3
-37
lines changed Expand file tree Collapse file tree 2 files changed +3
-37
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,6 @@ use regex::Regex;
15
15
16
16
use Indent ;
17
17
use config:: Config ;
18
- use utils:: round_up_to_power_of_two;
19
18
20
19
use MIN_STRING ;
21
20
@@ -41,7 +40,9 @@ pub fn rewrite_string<'a>(orig: &str, fmt: &StringFormat<'a>) -> Option<String>
41
40
let punctuation = ":,;." ;
42
41
43
42
let mut cur_start = 0 ;
44
- let mut result = String :: with_capacity ( round_up_to_power_of_two ( stripped_str. len ( ) ) ) ;
43
+ let mut result = String :: with_capacity ( stripped_str. len ( )
44
+ . checked_next_power_of_two ( )
45
+ . unwrap_or ( usize:: max_value ( ) ) ) ;
45
46
result. push_str ( fmt. opener ) ;
46
47
47
48
let ender_length = fmt. line_end . len ( ) ;
Original file line number Diff line number Diff line change @@ -180,33 +180,6 @@ pub fn trim_newlines(input: &str) -> &str {
180
180
}
181
181
}
182
182
183
- #[ inline]
184
- #[ cfg( target_pointer_width="64" ) ]
185
- // Based on the trick layed out at
186
- // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
187
- pub fn round_up_to_power_of_two ( mut x : usize ) -> usize {
188
- x = x. wrapping_sub ( 1 ) ;
189
- x |= x >> 1 ;
190
- x |= x >> 2 ;
191
- x |= x >> 4 ;
192
- x |= x >> 8 ;
193
- x |= x >> 16 ;
194
- x |= x >> 32 ;
195
- x. wrapping_add ( 1 )
196
- }
197
-
198
- #[ inline]
199
- #[ cfg( target_pointer_width="32" ) ]
200
- pub fn round_up_to_power_of_two ( mut x : usize ) -> usize {
201
- x = x. wrapping_sub ( 1 ) ;
202
- x |= x >> 1 ;
203
- x |= x >> 2 ;
204
- x |= x >> 4 ;
205
- x |= x >> 8 ;
206
- x |= x >> 16 ;
207
- x. wrapping_add ( 1 )
208
- }
209
-
210
183
// Macro for deriving implementations of Decodable for enums
211
184
#[ macro_export]
212
185
macro_rules! impl_enum_decodable {
@@ -344,11 +317,3 @@ fn bin_search_test() {
344
317
assert_eq ! ( Some ( ( ) ) , binary_search( 4 , 125 , & closure) ) ;
345
318
assert_eq ! ( None , binary_search( 6 , 100 , & closure) ) ;
346
319
}
347
-
348
- #[ test]
349
- fn power_rounding ( ) {
350
- assert_eq ! ( 0 , round_up_to_power_of_two( 0 ) ) ;
351
- assert_eq ! ( 1 , round_up_to_power_of_two( 1 ) ) ;
352
- assert_eq ! ( 64 , round_up_to_power_of_two( 33 ) ) ;
353
- assert_eq ! ( 256 , round_up_to_power_of_two( 256 ) ) ;
354
- }
You can’t perform that action at this time.
0 commit comments