Skip to content

Commit 04805bb

Browse files
committed
kernel_cmdline: Add algorithmic complexity comments to Extend impls
Signed-off-by: John Eckersberg <[email protected]>
1 parent 658cea0 commit 04805bb

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

crates/kernel_cmdline/src/bytes.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,13 @@ impl<'a> IntoIterator for &'a Cmdline<'a> {
268268

269269
impl<'a, 'other> Extend<Parameter<'other>> for Cmdline<'a> {
270270
fn extend<T: IntoIterator<Item = Parameter<'other>>>(&mut self, iter: T) {
271+
// Note this is O(N*M), but in practice this doesn't matter
272+
// because kernel cmdlines are typically quite small (limited
273+
// to at most 4k depending on arch). Using a hash-based
274+
// structure to reduce this to O(N)+C would likely raise the C
275+
// portion so much as to erase any benefit from removing the
276+
// combinatorial complexity. Plus CPUs are good at
277+
// caching/pipelining through contiguous memory.
271278
for param in iter {
272279
self.add(&param);
273280
}

crates/kernel_cmdline/src/utf8.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ impl<'a> IntoIterator for &'a Cmdline<'a> {
192192
}
193193

194194
impl<'a, 'other> Extend<Parameter<'other>> for Cmdline<'a> {
195+
// Note this is O(N*M), but in practice this doesn't matter
196+
// because kernel cmdlines are typically quite small (limited
197+
// to at most 4k depending on arch). Using a hash-based
198+
// structure to reduce this to O(N)+C would likely raise the C
199+
// portion so much as to erase any benefit from removing the
200+
// combinatorial complexity. Plus CPUs are good at
201+
// caching/pipelining through contiguous memory.
195202
fn extend<T: IntoIterator<Item = Parameter<'other>>>(&mut self, iter: T) {
196203
for param in iter {
197204
self.add(&param);

0 commit comments

Comments
 (0)