Skip to content

Commit 5886c27

Browse files
authored
Minor memory-related improvements in vortex-array and vortex-duckdb (#6299)
1. No need to clone the whole `BoolArray` when turning it into a `BitBuffer`, it contains a bunch of stuff we don't need, and that code path is identical to `into_bit_buffer`. 2. Addresses a small memory leak in `Value`'s `Display` implementation and rename some things. Signed-off-by: Adam Gutglick <adam@spiraldb.com>
1 parent f214085 commit 5886c27

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

vortex-array/src/arrays/bool/array.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,14 @@ impl BoolArray {
219219

220220
/// Returns the underlying [`BitBuffer`] of the array.
221221
pub fn to_bit_buffer(&self) -> BitBuffer {
222-
self.clone().into_bit_buffer()
222+
let buffer = self.bits.as_host().clone();
223+
224+
BitBuffer::new_with_offset(buffer, self.len, self.offset)
223225
}
224226

225227
/// Returns the underlying [`BitBuffer`] of the array
226228
pub fn into_bit_buffer(self) -> BitBuffer {
227-
let buffer = self.bits.as_host().clone();
228-
229-
BitBuffer::new_with_offset(buffer, self.len, self.offset)
229+
self.to_bit_buffer()
230230
}
231231

232232
pub fn to_mask(&self) -> Mask {

vortex-duckdb/src/duckdb/value.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ impl<'a> ValueRef<'a> {
159159

160160
impl<'a> Debug for ValueRef<'a> {
161161
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
162-
let debug = unsafe { cpp::duckdb_value_to_string(self.as_ptr()) };
163-
write!(f, "{}", unsafe { CStr::from_ptr(debug).to_string_lossy() })?;
164-
unsafe { cpp::duckdb_free(debug.cast()) };
162+
let ptr = unsafe { cpp::duckdb_value_to_string(self.as_ptr()) };
163+
write!(f, "{}", unsafe { CStr::from_ptr(ptr).to_string_lossy() })?;
164+
unsafe { cpp::duckdb_free(ptr.cast()) };
165165
Ok(())
166166
}
167167
}
@@ -248,11 +248,10 @@ impl Value {
248248

249249
impl Display for Value {
250250
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
251-
let debug = unsafe { cpp::duckdb_vx_value_to_string(self.as_ptr()) };
252-
let str = unsafe { CStr::from_ptr(debug) }
253-
.to_string_lossy()
254-
.to_string();
255-
f.write_str(&str)?;
251+
let ptr = unsafe { cpp::duckdb_vx_value_to_string(self.as_ptr()) };
252+
write!(f, "{}", unsafe { CStr::from_ptr(ptr) }.to_string_lossy())?;
253+
unsafe { cpp::duckdb_free(ptr.cast()) };
254+
256255
Ok(())
257256
}
258257
}
@@ -264,7 +263,7 @@ pub fn i128_from_parts(high: i64, low: u64) -> i128 {
264263

265264
impl Debug for Value {
266265
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
267-
f.write_str(&self.to_string())
266+
write!(f, "{self}",)
268267
}
269268
}
270269

0 commit comments

Comments
 (0)