]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
pgsql: convert transaction list to vecdeque
authorJason Ish <jason.ish@oisf.net>
Wed, 27 Apr 2022 15:47:19 +0000 (09:47 -0600)
committerVictor Julien <vjulien@oisf.net>
Sat, 30 Apr 2022 05:58:21 +0000 (07:58 +0200)
Allows for more efficient removal from front of the list.

Ticket: #5297

rust/src/pgsql/pgsql.rs
rust/src/rdp/rdp.rs

index ced155aef5295db690a14f3cc6d41c84f191d5f4..24dd2e1f677536181a3a95514696dca086039a5d 100644 (file)
@@ -25,6 +25,7 @@ use crate::conf::*;
 use crate::core::{AppProto, Flow, ALPROTO_FAILED, ALPROTO_UNKNOWN, IPPROTO_TCP};
 use nom7::{Err, IResult};
 use std;
+use std::collections::VecDeque;
 use std::ffi::CString;
 
 pub const PGSQL_CONFIG_DEFAULT_STREAM_DEPTH: u32 = 0;
@@ -116,7 +117,7 @@ pub enum PgsqlStateProgress {
 #[derive(Debug)]
 pub struct PgsqlState {
     tx_id: u64,
-    transactions: Vec<PgsqlTransaction>,
+    transactions: VecDeque<PgsqlTransaction>,
     request_gap: bool,
     response_gap: bool,
     backend_secret_key: u32,
@@ -138,7 +139,7 @@ impl PgsqlState {
     pub fn new() -> Self {
         Self {
             tx_id: 0,
-            transactions: Vec::new(),
+            transactions: VecDeque::new(),
             request_gap: false,
             response_gap: false,
             backend_secret_key: 0,
@@ -200,11 +201,11 @@ impl PgsqlState {
             || self.state_progress == PgsqlStateProgress::ConnectionTerminated
         {
             let tx = self.new_tx();
-            self.transactions.push(tx);
+            self.transactions.push_back(tx);
         }
         // If we don't need a new transaction, just return the current one
         SCLogDebug!("find_or_create state is {:?}", &self.state_progress);
-        return self.transactions.last_mut();
+        return self.transactions.back_mut();
     }
 
     /// Process State progress to decide if PgsqlTransaction is finished
@@ -385,7 +386,7 @@ impl PgsqlState {
             PgsqlBEMessage::RowDescription(_) => Some(PgsqlStateProgress::RowDescriptionReceived),
             PgsqlBEMessage::ConsolidatedDataRow(msg) => {
                 // Increment tx.data_size here, since we know msg type, so that we can later on log that info
-                self.transactions.last_mut()?.sum_data_size(msg.data_size);
+                self.transactions.back_mut()?.sum_data_size(msg.data_size);
                 Some(PgsqlStateProgress::DataRowReceived)
             }
             PgsqlBEMessage::CommandComplete(_) => {
index 8479530676b4594d8d8853a0f17adb5a6e45c24f..7fc0b505581eaa52a96724cb80ffb8ecacb38146 100644 (file)
@@ -631,9 +631,9 @@ mod tests {
         let tx0 = state.new_tx(item0);
         let tx1 = state.new_tx(item1);
         let tx2 = state.new_tx(item2);
-        state.transactions.push(tx0);
-        state.transactions.push(tx1);
-        state.transactions.push(tx2);
+        state.transactions.push_back(tx0);
+        state.transactions.push_back(tx1);
+        state.transactions.push_back(tx2);
         assert_eq!(Some(&state.transactions[1]), state.get_tx(2));
     }