Skip to content

Commit

Permalink
update read_many_structs
Browse files Browse the repository at this point in the history
  • Loading branch information
zslayton committed Jan 3, 2025
1 parent 4a945c8 commit b2d65fd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ compact_str = "0.8.0"
chrono = { version = "0.4", default-features = false, features = ["clock", "std", "wasmbind"] }
delegate = "0.12.0"
thiserror = "1.0"
winnow = "0.6"
winnow = { version = "0.6", features = ["simd"] }
num-integer = "0.1.44"
num-traits = "0.2"
arrayvec = "0.7"
Expand Down
6 changes: 3 additions & 3 deletions benches/read_many_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,12 @@ mod benchmark {
b.iter(|| {
// We don't have an API for doing this with the application-level reader yet, so
// for now we use a manually configured context and a raw reader.
let mut reader = LazyRawBinaryReader_1_1::new(binary_1_1_data);
let mut reader = LazyRawBinaryReader_1_1::new(context_ref, binary_1_1_data);
let mut num_top_level_values: usize = 0;
// Skip past the IVM
reader.next(context_ref).unwrap().expect_ivm().unwrap();
reader.next().unwrap().expect_ivm().unwrap();
// Expect every top-level item to be an e-expression.
while let RawStreamItem::EExp(raw_eexp) = reader.next(context_ref).unwrap() {
while let RawStreamItem::EExp(raw_eexp) = reader.next().unwrap() {
num_top_level_values += 1;
// Look up the e-expression's invoked macro ID in the encoding context.
let eexp = raw_eexp.resolve(context_ref).unwrap();
Expand Down
1 change: 1 addition & 0 deletions profile.json

Large diffs are not rendered by default.

37 changes: 3 additions & 34 deletions src/lazy/text/matched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ impl MatchedString {
matched_input: TextBuffer<'data>,
) -> IonResult<StrRef<'data>> {
// Take a slice of the input that ignores the first and last bytes, which are quotes.
let body = matched_input.slice(1, dbg!(matched_input.len()) - 2);
let body = matched_input.slice(1, matched_input.len() - 2);
// There are no escaped characters, so we can just validate the string in-place.
let text = body.as_text()?;
let str_ref = StrRef::from(text);
Expand Down Expand Up @@ -1490,8 +1490,8 @@ mod tests {
// our fabricated value off of the input before reading.
let encoding_context = EncodingContext::empty();
let context = encoding_context.get_ref();
let buffer = TextBuffer::new(context, dbg!(data).as_bytes(), true);
let matched = dbg!(buffer.clone().match_string().unwrap());
let buffer = TextBuffer::new(context, data.as_bytes(), true);
let matched = buffer.clone().match_string().unwrap();
let actual = matched.read(context.allocator(), buffer).unwrap();
assert_eq!(
actual, expected,
Expand Down Expand Up @@ -1522,37 +1522,6 @@ mod tests {
Ok(())
}

#[test]
fn read_strings_foo() -> IonResult<()> {
fn expect_string(data: &str, expected: &str) {
// Ordinarily the reader is responsible for indicating that the input is complete.
// For the sake of these tests, we're going to append one more value (`0`) to the input
// stream so the parser knows that the long-form strings are complete. We then trim
// our fabricated value off of the input before reading.
let encoding_context = EncodingContext::empty();
let context = encoding_context.get_ref();
let buffer = TextBuffer::new(context, dbg!(data).as_bytes(), true);
let matched = dbg!(buffer.clone().match_string().unwrap());
let actual = matched.read(context.allocator(), buffer).unwrap();
assert_eq!(
actual, expected,
"Actual didn't match expected for input '{}'.\n{:?}\n!=\n{:?}",
data, actual, expected
);
}

let tests = [
// In long-form strings, all unescaped newlines are converted to `\n`.
("'''foo\rbar\r\nbaz'''", "foo\nbar\nbaz"),
];

for (input, expected) in tests {
expect_string(input, expected);
}

Ok(())
}

#[test]
fn read_clobs() -> IonResult<()> {
fn read_clob<'a>(
Expand Down

0 comments on commit b2d65fd

Please sign in to comment.