@@ -47,9 +47,9 @@ use std::{
4747///
4848/// Specification: `QTDEX-A/BQL-S1`
4949pub 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
5555impl 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