Skip to content

Commit b729685

Browse files
committed
Add check_invariants to make sure we don't create heap storage for small vecs
1 parent ec44135 commit b729685

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/storage.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,17 @@ mod tests {
8080
}
8181
}
8282

83+
fn check_invariants(storage: Storage) -> bool {
84+
match storage {
85+
Storage::Inline(len, _) => len as usize <= MAX_INLINE,
86+
Storage::Heap(arc) => arc.len() > MAX_INLINE,
87+
}
88+
}
89+
8390
quickcheck! {
8491
fn roundtrip_check(data: Vec<u8>) -> bool {
8592
let storage = Storage::from_slice(&data);
86-
storage.bytes() == data.as_slice()
93+
storage.bytes() == data.as_slice() && check_invariants(storage)
8794
}
8895

8996
fn from_slices_roundtrip_check(data: Vec<Vec<u8>>) -> bool {
@@ -94,7 +101,7 @@ mod tests {
94101
expected.extend_from_slice(&v);
95102
}
96103
let storage = Storage::from_slices(&slices);
97-
storage.bytes() == expected.as_slice()
104+
storage.bytes() == expected.as_slice() && check_invariants(storage)
98105
}
99106
}
100107
}

0 commit comments

Comments
 (0)