Buffer Move Semantics #3920
flatcap
started this conversation in
Development
Replies: 1 comment
-
I like the explicitness of having two functions: void buf_move_str(struct Buffer *buf_dest, const char **ptr);
void buf_move_str_n(struct Buffer *buf_dest, const char **ptr, size_t len); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Now that
Buffer
s are starting to take off, it's time to use them more efficiently.There are ~40
buf_copy()
s and ~200buf_strcpy()
s, where an existing string is copied.Many of these source strings are just freed afterwards.
Following navi's ideas on IRC, how about:
In
buf_move_str()
, the destBuffer
needs to know the length of the allocation.Using
strlen()
would be good enough.Alternatively, we could add a
int len
param.If we know then length, pass it, if not pass
-1
and usestrlen()
in the function.Another possibly useful function is:
Care would be needed when dealing with the
BufferPool
.Beta Was this translation helpful? Give feedback.
All reactions