Skip to content

Commit 0fbf6bf

Browse files
authored
block-padding: replace block iteration with fill() (#934)
1 parent 9349bbd commit 0fbf6bf

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

block-padding/src/lib.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,7 @@ impl RawPadding for ZeroPadding {
138138
if pos > block.len() {
139139
panic!("`pos` is bigger than block size");
140140
}
141-
for b in &mut block[pos..] {
142-
*b = 0;
143-
}
141+
block[pos..].fill(0);
144142
}
145143

146144
#[inline]
@@ -207,9 +205,7 @@ impl RawPadding for Pkcs7 {
207205
panic!("`pos` is bigger or equal to block size");
208206
}
209207
let n = (block.len() - pos) as u8;
210-
for b in &mut block[pos..] {
211-
*b = n;
212-
}
208+
block[pos..].fill(n);
213209
}
214210

215211
#[inline]
@@ -286,9 +282,7 @@ impl RawPadding for AnsiX923 {
286282
panic!("`pos` is bigger or equal to block size");
287283
}
288284
let bs = block.len();
289-
for b in &mut block[pos..bs - 1] {
290-
*b = 0;
291-
}
285+
block[pos..bs - 1].fill(0);
292286
block[bs - 1] = (bs - pos) as u8;
293287
}
294288

@@ -338,9 +332,7 @@ impl RawPadding for Iso7816 {
338332
panic!("`pos` is bigger or equal to block size");
339333
}
340334
block[pos] = 0x80;
341-
for b in &mut block[pos + 1..] {
342-
*b = 0;
343-
}
335+
block[pos + 1..].fill(0);
344336
}
345337

346338
#[inline]

0 commit comments

Comments
 (0)