Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
reuse scratch when reading dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jun 26, 2022
1 parent ede4df3 commit 562435e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/io/ipc/append/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ impl<R: Read + Seek + Write> FileWriter<R> {
));
}

let dictionaries = read::read_file_dictionaries(&mut writer, &metadata)?;
let dictionaries =
read::read_file_dictionaries(&mut writer, &metadata, &mut Default::default())?;

let last_block = metadata.blocks.last().ok_or_else(|| {
Error::oos("An Arrow IPC file must have at least 1 message (the schema message)")
Expand Down
1 change: 1 addition & 0 deletions src/io/ipc/read/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ impl ReadBuffer {
/// method on `Vec` this is `safe` because this function guarantees that
/// the underlying data always is initialized.
pub fn set_len(&mut self, length: usize) {
dbg!(length, self.data.len(), self.data.capacity());
if length > self.data.capacity() {
self.data = vec![0; length];
} else if length > self.data.len() {
Expand Down
10 changes: 7 additions & 3 deletions src/io/ipc/read/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ fn read_dictionary_block<R: Read + Seek>(
pub fn read_file_dictionaries<R: Read + Seek>(
reader: &mut R,
metadata: &FileMetadata,
scratch: &mut ReadBuffer,
) -> Result<Dictionaries> {
let mut dictionaries = Default::default();
let mut data = vec![].into();

let blocks = if let Some(blocks) = metadata.dictionaries.as_deref() {
blocks
Expand All @@ -127,7 +127,7 @@ pub fn read_file_dictionaries<R: Read + Seek>(
};

for block in blocks {
read_dictionary_block(reader, metadata, block, &mut dictionaries, &mut data)?;
read_dictionary_block(reader, metadata, block, &mut dictionaries, scratch)?;
}
Ok(dictionaries)
}
Expand Down Expand Up @@ -343,7 +343,11 @@ impl<R: Read + Seek> FileReader<R> {

fn read_dictionaries(&mut self) -> Result<()> {
if self.dictionaries.is_none() {
self.dictionaries = Some(read_file_dictionaries(&mut self.reader, &self.metadata)?);
self.dictionaries = Some(read_file_dictionaries(
&mut self.reader,
&self.metadata,
&mut self.buffer,
)?);
};
Ok(())
}
Expand Down

0 comments on commit 562435e

Please sign in to comment.