Skip to content

Commit b42042b

Browse files
nyurikdanielrh
authored andcommitted
Clean up some nested curly braces
I used a very powerful tool [coccinelle](https://gitlab.inria.fr/coccinelle/coccinelleforrust) (its C version is used for Linux kernel refactorings). Highly recommend installing it as it has a potential to simplify refactorings while not dealing with regex errors. To install it, run ```sh cargo install --git https://gitlab.inria.fr/coccinelle/coccinelleforrust ``` Afterward, create this file as `target/repl.cocci` with the following content. Using `target/` ensures that it will be ignored by git. ```diff @@ @@ { - { ... - } } ``` and run this command from the root of the repo: ```shell cfr --apply -c target/repl.cocci src/ cargo fmt --all ``` Afterwards, I manually reverted two macro_rules! changes -- those are the only ones that should continue having nested curlies.
1 parent b9a4857 commit b42042b

File tree

13 files changed

+121
-201
lines changed

13 files changed

+121
-201
lines changed

src/enc/backward_references/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,9 +2463,7 @@ fn CreateBackwardReferences<AH: AnyHasher>(
24632463
} < 4i32
24642464
&& (position.wrapping_add(hasher.HashTypeLength()) < pos_end)
24652465
{
2466-
{
2467-
break 'continue7;
2468-
}
2466+
break 'continue7;
24692467
}
24702468
}
24712469
break 'break6;

src/enc/bit_cost.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,7 @@ pub fn BrotliPopulationCost<HistogramType: SliceWrapper<u32> + CostAccessors>(
266266
s[count as usize] = i;
267267
count += 1;
268268
if count > 4i32 {
269-
{
270-
break 'break1;
271-
}
269+
break 'break1;
272270
}
273271
}
274272
}
@@ -346,9 +344,7 @@ pub fn BrotliPopulationCost<HistogramType: SliceWrapper<u32> + CostAccessors>(
346344
}
347345
i += reps as usize;
348346
if i == data_size {
349-
{
350-
break;
351-
}
347+
break;
352348
}
353349
if reps < 3 {
354350
depth_histo[0] += reps

src/enc/block_splitter.rs

Lines changed: 68 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -342,82 +342,80 @@ where
342342
*item = 0;
343343
}
344344
for (byte_ix, data_byte_ix) in data[..length].iter().enumerate() {
345-
{
346-
let block_id_ptr = &mut block_id[byte_ix];
347-
let ix: usize = byte_ix.wrapping_mul(bitmaplen);
348-
let insert_cost_ix: usize =
349-
u64::from(data_byte_ix.clone()).wrapping_mul(num_histograms as u64) as usize;
350-
let mut min_cost: super::util::floatX = 1e38 as super::util::floatX;
351-
let mut block_switch_cost: super::util::floatX = block_switch_bitcost;
352-
if false {
353-
// nonvectorized version: same code below
354-
for (k, insert_cost_iter) in insert_cost
355-
[insert_cost_ix..(insert_cost_ix + num_histograms)]
356-
.iter()
357-
.enumerate()
358-
{
359-
let cost_iter = &mut cost[(k >> 3)][k & 7];
360-
*cost_iter += *insert_cost_iter;
361-
if *cost_iter < min_cost {
362-
min_cost = *cost_iter;
363-
*block_id_ptr = k as u8;
364-
}
365-
}
366-
} else {
367-
// main (vectorized) loop
368-
let insert_cost_slice = insert_cost.split_at(insert_cost_ix).1;
369-
for (v_index, cost_iter) in cost
370-
.split_at_mut(num_histograms >> 3)
371-
.0
372-
.iter_mut()
373-
.enumerate()
374-
{
375-
let base_index = v_index << 3;
376-
let mut local_insert_cost = [0.0 as super::util::floatX; 8];
377-
local_insert_cost
378-
.clone_from_slice(insert_cost_slice.split_at(base_index).1.split_at(8).0);
379-
for sub_index in 0usize..8usize {
380-
cost_iter[sub_index] += local_insert_cost[sub_index];
381-
let final_cost = cost_iter[sub_index];
382-
if final_cost < min_cost {
383-
min_cost = final_cost;
384-
*block_id_ptr = (base_index + sub_index) as u8;
385-
}
386-
}
345+
let block_id_ptr = &mut block_id[byte_ix];
346+
let ix: usize = byte_ix.wrapping_mul(bitmaplen);
347+
let insert_cost_ix: usize =
348+
u64::from(data_byte_ix.clone()).wrapping_mul(num_histograms as u64) as usize;
349+
let mut min_cost: super::util::floatX = 1e38 as super::util::floatX;
350+
let mut block_switch_cost: super::util::floatX = block_switch_bitcost;
351+
if false {
352+
// nonvectorized version: same code below
353+
for (k, insert_cost_iter) in insert_cost
354+
[insert_cost_ix..(insert_cost_ix + num_histograms)]
355+
.iter()
356+
.enumerate()
357+
{
358+
let cost_iter = &mut cost[(k >> 3)][k & 7];
359+
*cost_iter += *insert_cost_iter;
360+
if *cost_iter < min_cost {
361+
min_cost = *cost_iter;
362+
*block_id_ptr = k as u8;
387363
}
388-
let vectorized_offset = ((num_histograms >> 3) << 3);
389-
let mut k = vectorized_offset;
390-
//remainder loop for
391-
for insert_cost_iter in insert_cost
392-
.split_at(insert_cost_ix + vectorized_offset)
393-
.1
394-
.split_at(num_histograms & 7)
395-
.0
396-
.iter()
397-
{
398-
let cost_iter = &mut cost[(k >> 3)];
399-
cost_iter[k & 7] += *insert_cost_iter;
400-
if cost_iter[k & 7] < min_cost {
401-
min_cost = cost_iter[k & 7];
402-
*block_id_ptr = k as u8;
364+
}
365+
} else {
366+
// main (vectorized) loop
367+
let insert_cost_slice = insert_cost.split_at(insert_cost_ix).1;
368+
for (v_index, cost_iter) in cost
369+
.split_at_mut(num_histograms >> 3)
370+
.0
371+
.iter_mut()
372+
.enumerate()
373+
{
374+
let base_index = v_index << 3;
375+
let mut local_insert_cost = [0.0 as super::util::floatX; 8];
376+
local_insert_cost
377+
.clone_from_slice(insert_cost_slice.split_at(base_index).1.split_at(8).0);
378+
for sub_index in 0usize..8usize {
379+
cost_iter[sub_index] += local_insert_cost[sub_index];
380+
let final_cost = cost_iter[sub_index];
381+
if final_cost < min_cost {
382+
min_cost = final_cost;
383+
*block_id_ptr = (base_index + sub_index) as u8;
403384
}
404-
k += 1;
405385
}
406386
}
407-
if byte_ix < 2000usize {
408-
block_switch_cost *= (0.77 as super::util::floatX
409-
+ 0.07 as super::util::floatX * byte_ix as (super::util::floatX)
410-
/ 2000i32 as (super::util::floatX));
387+
let vectorized_offset = ((num_histograms >> 3) << 3);
388+
let mut k = vectorized_offset;
389+
//remainder loop for
390+
for insert_cost_iter in insert_cost
391+
.split_at(insert_cost_ix + vectorized_offset)
392+
.1
393+
.split_at(num_histograms & 7)
394+
.0
395+
.iter()
396+
{
397+
let cost_iter = &mut cost[(k >> 3)];
398+
cost_iter[k & 7] += *insert_cost_iter;
399+
if cost_iter[k & 7] < min_cost {
400+
min_cost = cost_iter[k & 7];
401+
*block_id_ptr = k as u8;
402+
}
403+
k += 1;
411404
}
412-
update_cost_and_signal(
413-
num_histograms as u32,
414-
ix,
415-
min_cost,
416-
block_switch_cost,
417-
cost,
418-
switch_signal,
419-
);
420405
}
406+
if byte_ix < 2000usize {
407+
block_switch_cost *= (0.77 as super::util::floatX
408+
+ 0.07 as super::util::floatX * byte_ix as (super::util::floatX)
409+
/ 2000i32 as (super::util::floatX));
410+
}
411+
update_cost_and_signal(
412+
num_histograms as u32,
413+
ix,
414+
min_cost,
415+
block_switch_cost,
416+
cost,
417+
switch_signal,
418+
);
421419
}
422420
{
423421
let mut byte_ix: usize = length.wrapping_sub(1);

src/enc/brotli_bit_stream.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -832,9 +832,7 @@ fn BrotliStoreHuffmanTreeOfHuffmanTreeToBitMask(
832832
as i32
833833
!= 0i32
834834
{
835-
{
836-
break 'break5;
837-
}
835+
break 'break5;
838836
}
839837
}
840838
codes_to_store = codes_to_store.wrapping_sub(1);
@@ -940,9 +938,7 @@ pub fn BrotliStoreHuffmanTree(
940938
} else if num_codes == 1i32 {
941939
num_codes = 2i32;
942940
{
943-
{
944-
break 'break3;
945-
}
941+
break 'break3;
946942
}
947943
}
948944
}
@@ -1117,9 +1113,7 @@ pub fn BrotliBuildAndStoreHuffmanTreeFast<AllocHT: alloc::Allocator<HuffmanTree>
11171113
k -= 1;
11181114
}
11191115
if BrotliSetDepth(2i32 * n - 1i32, tree.slice_mut(), depth, 14i32) {
1120-
{
1121-
break 'break11;
1122-
}
1116+
break 'break11;
11231117
}
11241118
}
11251119
}
@@ -1574,9 +1568,7 @@ fn BuildAndStoreHuffmanTree(
15741568
if count < 4usize {
15751569
s4[count] = i;
15761570
} else if count > 4usize {
1577-
{
1578-
break 'break31;
1579-
}
1571+
break 'break31;
15801572
}
15811573
count = count.wrapping_add(1);
15821574
}
@@ -1919,9 +1911,7 @@ fn RunLengthCodeZeros(
19191911
v[*out_size] = run_length_prefix.wrapping_add(extra_bits << 9);
19201912
*out_size = out_size.wrapping_add(1);
19211913
{
1922-
{
1923-
break;
1924-
}
1914+
break;
19251915
}
19261916
} else {
19271917
let extra_bits: u32 = (1u32 << max_prefix).wrapping_sub(1);

src/enc/cluster.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ pub fn BrotliHistogramCombine<
178178
cost_diff_threshold = 1e38 as super::util::floatX;
179179
min_cluster_size = max_clusters;
180180
{
181-
{
182-
continue;
183-
}
181+
continue;
184182
}
185183
}
186184
/* Take the best pair from the top of heap. */
@@ -229,9 +227,7 @@ pub fn BrotliHistogramCombine<
229227
|| (p).idx2 == best_idx2
230228
{
231229
/* Remove invalid pair from the queue. */
232-
{
233-
break 'continue12;
234-
}
230+
break 'continue12;
235231
}
236232
if HistogramPairIsLess(&pairs[0], &p) {
237233
/* Replace the top of the queue if needed. */

src/enc/compress_fragment.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,8 @@ fn EmitCopyLenLastDistance(
458458
}
459459

460460
fn HashBytesAtOffset(v: u64, offset: i32, shift: usize) -> u32 {
461-
{
462-
let h: u64 = (v >> (8i32 * offset) << 24).wrapping_mul(kHashMul32 as (u64));
463-
(h >> shift) as u32
464-
}
461+
let h: u64 = (v >> (8i32 * offset) << 24).wrapping_mul(kHashMul32 as (u64));
462+
(h >> shift) as u32
465463
}
466464

467465
fn EmitCopyLen(

src/enc/compress_fragment_two_pass.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,7 @@ fn CreateCommands(
212212
if next_ip > ip_limit {
213213
goto_emit_remainder = 1i32;
214214
{
215-
{
216-
break 'break3;
217-
}
215+
break 'break3;
218216
}
219217
}
220218
next_hash = Hash(&base_ip[next_ip..], shift, min_match);
@@ -225,9 +223,7 @@ fn CreateCommands(
225223
{
226224
table[(hash as usize)] = ip_index.wrapping_sub(0) as i32;
227225
{
228-
{
229-
break 'break3;
230-
}
226+
break 'break3;
231227
}
232228
}
233229
candidate = table[(hash as usize)] as usize;
@@ -248,9 +244,7 @@ fn CreateCommands(
248244
}
249245
}
250246
if goto_emit_remainder != 0 {
251-
{
252-
break;
253-
}
247+
break;
254248
}
255249
{
256250
let base: usize = ip_index;
@@ -283,9 +277,7 @@ fn CreateCommands(
283277
if ip_index >= ip_limit {
284278
goto_emit_remainder = 1i32;
285279
{
286-
{
287-
break;
288-
}
280+
break;
289281
}
290282
}
291283
{
@@ -342,9 +334,7 @@ fn CreateCommands(
342334
if ip_index >= ip_limit {
343335
goto_emit_remainder = 1i32;
344336
{
345-
{
346-
break;
347-
}
337+
break;
348338
}
349339
}
350340
{

0 commit comments

Comments
 (0)