Skip to content

Commit f80765f

Browse files
Address PR feedback for 5-byte encoding of string refs.
1 parent 72cb8fa commit f80765f

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

analyzeme/src/stringtable.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,12 @@ impl<'st> StringRef<'st> {
148148
// String IDs in the table data are encoded in big endian format, while string
149149
// IDs in the index are encoded in little endian format. Don't mix the two up.
150150
fn decode_string_ref_from_data(bytes: &[u8]) -> StringId {
151+
// The code below assumes we use a 5-byte encoding for string
152+
// refs, where the first byte is STRING_REF_TAG and the
153+
// following 4 bytes are a little-endian u32 string ID value.
151154
assert!(bytes[0] == STRING_REF_TAG);
152155
assert!(STRING_REF_ENCODED_SIZE == 5);
156+
153157
let id = u32::from_le_bytes(bytes[1..5].try_into().unwrap());
154158
StringId::new(id)
155159
}

measureme/src/stringtable.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ impl<'s> StringComponent<'s> {
180180
&mut bytes[s.len()..]
181181
}
182182
StringComponent::Ref(string_id) => {
183+
// The code below assumes we use a 5-byte encoding for string
184+
// refs, where the first byte is STRING_REF_TAG and the
185+
// following 4 bytes are a little-endian u32 string ID value.
183186
assert!(STRING_REF_ENCODED_SIZE == 5);
187+
184188
bytes[0] = STRING_REF_TAG;
185189
&mut bytes[1..5].copy_from_slice(&string_id.0.to_le_bytes());
186190
&mut bytes[5..]

0 commit comments

Comments
 (0)