Skip to content

Commit 01bcefb

Browse files
committed
Reduce allocations and tag 0.8.6
1 parent 148830e commit 01bcefb

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All changes in this project will be noted in this file.
44

5+
### 0.8.6
6+
7+
Reduced allocations in `Query`.
8+
59
### 0.8.5
610

711
Fixed bugs with the derive macros.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ license = "Apache-2.0"
99
name = "skytable"
1010
readme = "README.md"
1111
repository = "https://github.com/skytable/client-rust"
12-
version = "0.8.5"
12+
version = "0.8.6"
1313

1414
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1515
[dependencies]

src/query.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ use std::{
4747
///
4848
/// Specification: `QTDEX-A/BQL-S1`
4949
pub struct Query {
50-
dataframe_q: Box<[u8]>,
51-
dataframe_p: Vec<u8>,
50+
buf: Vec<u8>,
5251
param_cnt: usize,
52+
q_window: usize,
5353
}
5454

5555
impl From<String> for Query {
@@ -74,19 +74,20 @@ impl Query {
7474
Self::_new(query)
7575
}
7676
fn _new(query: String) -> Self {
77+
let l = query.len();
7778
Self {
78-
dataframe_q: query.into_bytes().into_boxed_slice(),
79-
dataframe_p: vec![],
79+
buf: query.into_bytes(),
8080
param_cnt: 0,
81+
q_window: l,
8182
}
8283
}
8384
/// Returns a reference to the query string
8485
pub fn query_str(&self) -> &str {
85-
unsafe { core::str::from_utf8_unchecked(&self.dataframe_q) }
86+
unsafe { core::str::from_utf8_unchecked(&self.buf[..self.q_window]) }
8687
}
8788
/// Add a new parameter to the query
8889
pub fn push_param(&mut self, param: impl SQParam) -> &mut Self {
89-
self.param_cnt += param.append_param(&mut self.dataframe_p);
90+
self.param_cnt += param.append_param(&mut self.buf);
9091
self
9192
}
9293
/// Get the number of parameters
@@ -102,10 +103,9 @@ impl Query {
102103
// compute the total packet size
103104
// q window
104105
let mut query_window_buffer = itoa::Buffer::new();
105-
let query_window_str = query_window_buffer.format(self.dataframe_q.len());
106+
let query_window_str = query_window_buffer.format(self.q_window);
106107
// full packet
107-
let total_packet_size =
108-
query_window_str.len() + 1 + self.dataframe_q.len() + self.dataframe_p.len();
108+
let total_packet_size = query_window_str.len() + 1 + self.buf.len();
109109
let mut total_packet_size_buffer = itoa::Buffer::new();
110110
let total_packet_size_str = total_packet_size_buffer.format(total_packet_size);
111111
// segment 1: meta
@@ -116,8 +116,7 @@ impl Query {
116116
buf.write_all(query_window_str.as_bytes())?;
117117
buf.write_all(b"\n")?;
118118
// segment 3: payload
119-
buf.write_all(&self.dataframe_q)?;
120-
buf.write_all(&self.dataframe_p)?;
119+
buf.write_all(&self.buf)?;
121120
Ok(())
122121
}
123122
#[inline(always)]

0 commit comments

Comments
 (0)