Skip to content

Commit

Permalink
Avoid appending the empty string
Browse files Browse the repository at this point in the history
Unfortunately, appending the empty string to another string results in a
potentially expensive copy.
  • Loading branch information
reynir committed Apr 8, 2024
1 parent 251bed1 commit 0de5ad0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/engine.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,11 @@ let incoming ?(is_not_taken = fun _ip -> false) state control_crypto buf =
if String.length linger = 0 then Ok (state, out, payloads, act_opt)
else multi linger (state, out, payloads, act_opt)
in
let r = multi (state.linger ^ buf) (state, [], [], None) in
(* ["" ^ buf] is not cheap :/ *)
let buf =
if String.length state.linger = 0 then buf else state.linger ^ buf
in
let r = multi buf (state, [], [], None) in
let+ s', out, payloads, act_opt = udp_ignore r in
Log.debug (fun m -> m "out state is %a" State.pp s');
Log.debug (fun m -> m "%u outgoing packets" (List.length out));
Expand Down

0 comments on commit 0de5ad0

Please sign in to comment.