Skip to content

Commit

Permalink
Merge pull request #713 from mlowicki/mlowicki/optimise_ownedheaders_…
Browse files Browse the repository at this point in the history
…insert

Get rid of CString alloc in OwnedHeader::insert
  • Loading branch information
davidblewett authored Oct 8, 2024
2 parents b2bcf19 + 02a1658 commit f71185c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/message.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Store and manipulate Kafka messages.
use std::ffi::{CStr, CString};
use std::ffi::CStr;
use std::fmt;
use std::marker::PhantomData;
use std::os::raw::c_void;
use std::os::raw::{c_char, c_void};
use std::ptr;
use std::str;
use std::sync::Arc;
Expand Down Expand Up @@ -534,7 +534,6 @@ impl OwnedHeaders {
where
V: ToBytes + ?Sized,
{
let name_cstring = CString::new(header.key).unwrap();
let (value_ptr, value_len) = match header.value {
None => (ptr::null_mut(), 0),
Some(value) => {
Expand All @@ -548,8 +547,8 @@ impl OwnedHeaders {
let err = unsafe {
rdsys::rd_kafka_header_add(
self.ptr(),
name_cstring.as_ptr(),
name_cstring.as_bytes().len() as isize,
header.key.as_ptr() as *const c_char,
header.key.as_bytes().len() as isize,
value_ptr,
value_len,
)
Expand Down

0 comments on commit f71185c

Please sign in to comment.