Skip to content

Commit

Permalink
optimize (slight) string serialization
Browse files Browse the repository at this point in the history
w/ memcpy()
  • Loading branch information
mdavidsaver committed Nov 11, 2023
1 parent 87322ef commit b8f42dc
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/pvaproto.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,23 +362,29 @@ void from_wire(Buffer& buf, Selector& sel)
}

inline
void to_wire(Buffer& buf, const char *s)
void to_wire_str(Buffer& buf, const char *s, size_t cnt)
{
Size len{s ? strlen(s) : 0};
Size len{cnt};
to_wire(buf, len);
if(!buf.ensure(len.size)) {
buf.fault(__FILE__, __LINE__);

} else {
for(size_t i=0; i<len.size; i++)
buf.push(s[i]);
memcpy(buf.save(), s, len.size);
buf._skip(len.size);
}

}

inline
void to_wire(Buffer& buf, const char *s)
{
to_wire_str(buf, s, s ? strlen(s) : 0);
}

inline void to_wire(Buffer& buf, const std::string& s)
{
to_wire(buf, s.c_str());
to_wire_str(buf, s.c_str(), s.size());
}

inline
Expand Down

0 comments on commit b8f42dc

Please sign in to comment.