Skip to content

Commit

Permalink
buffer: drop buffer_move function
Browse files Browse the repository at this point in the history
  • Loading branch information
rnpnr committed Jan 12, 2025
1 parent 1b483c2 commit f2b2337
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 28 deletions.
6 changes: 0 additions & 6 deletions buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,6 @@ const char *buffer_content0(Buffer *buf) {
return buf->data;
}

char *buffer_move(Buffer *buf) {
char *data = buf->data;
*buf = (Buffer){0};
return data;
}

ssize_t read_into_buffer(void *context, char *data, size_t len) {
buffer_append(context, data, len);
return len;
Expand Down
7 changes: 0 additions & 7 deletions buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ size_t buffer_length0(Buffer*);
* Guaranteed to return a NUL terminated string even if buffer is empty.
*/
const char *buffer_content0(Buffer*);
/**
* Borrow underlying buffer data.
* @rst
* .. warning:: The caller is responsible to ``free(3)`` it.
* @endrst
*/
char *buffer_move(Buffer*);

/** ``read(3p)`` like interface for reading into a Buffer (``context``) */
ssize_t read_into_buffer(void *context, char *data, size_t len);
Expand Down
6 changes: 3 additions & 3 deletions sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ static char *parse_until(const char **s, const char *until, const char *escchars

buffer_terminate(&buf);

return buffer_move(&buf);
return buf.data;
}

static char *parse_delimited(const char **s, int type) {
Expand Down Expand Up @@ -645,7 +645,7 @@ static char *parse_text(const char **s, Count *count) {
return NULL;
}

return buffer_move(&buf);
return buf.data;
}

static char *parse_shellcmd(Vis *vis, const char **s) {
Expand Down Expand Up @@ -683,7 +683,7 @@ static char *parse_cmdname(const char **s) {

buffer_terminate(&buf);

return buffer_move(&buf);
return buf.data;
}

static Regex *parse_regex(Vis *vis, const char **s) {
Expand Down
7 changes: 1 addition & 6 deletions test/core/buffer-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ int main(int argc, char *argv[]) {
ok(buffer_append(&buf, "\0baz", 4) && compare(&buf, "foo\0bar\0baz", 11), "Append data");

ok(buffer_grow(&buf, cap+1) && compare(&buf, "foo\0bar\0baz", 11) && buf.size >= cap+1, "Grow");

const char *content = buf.data;
char *data = buffer_move(&buf);
ok(data == content && buf.len == 0 && buf.size == 0 && buf.data == NULL, "Move");
ok(buffer_append0(&buf, "foo") && buf.data != data, "Modify after move");
free(data);
buf.len = 0;

skip_if(TIS_INTERPRETER, 1, "vsnprintf not supported") {

Expand Down
8 changes: 2 additions & 6 deletions vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -1861,12 +1861,8 @@ static int _vis_pipe_collect(Vis *vis, File *file, Filerange *range, const char*
fullscreen);
buffer_terminate(&bufout);
buffer_terminate(&buferr);
if (out)
*out = buffer_move(&bufout);
if (err)
*err = buffer_move(&buferr);
buffer_release(&bufout);
buffer_release(&buferr);
if (out) *out = bufout.data;
if (err) *err = buferr.data;
return status;
}

Expand Down

0 comments on commit f2b2337

Please sign in to comment.