Skip to content

Commit 4c3169b

Browse files
committed
vcs-svn: avoid unnecessary copying of log message and author
Use strbuf_swap when storing the svn:log and svn:author properties, so pointers to rather than the contents of buffers get copied. The main effect should be to make the code a little easier to read. Signed-off-by: Jonathan Nieder <[email protected]>
1 parent 7e2fe3a commit 4c3169b

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

vcs-svn/svndump.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static void reset_dump_ctx(const char *url)
8383
}
8484

8585
static void handle_property(const struct strbuf *key_buf,
86-
const char *val, uint32_t len,
86+
struct strbuf *val,
8787
uint32_t *type_set)
8888
{
8989
const char *key = key_buf->buf;
@@ -95,23 +95,23 @@ static void handle_property(const struct strbuf *key_buf,
9595
break;
9696
if (!val)
9797
die("invalid dump: unsets svn:log");
98-
strbuf_reset(&rev_ctx.log);
99-
strbuf_add(&rev_ctx.log, val, len);
98+
strbuf_swap(&rev_ctx.log, val);
10099
break;
101100
case sizeof("svn:author"):
102101
if (constcmp(key, "svn:author"))
103102
break;
104-
strbuf_reset(&rev_ctx.author);
105-
if (val)
106-
strbuf_add(&rev_ctx.author, val, len);
103+
if (!val)
104+
strbuf_reset(&rev_ctx.author);
105+
else
106+
strbuf_swap(&rev_ctx.author, val);
107107
break;
108108
case sizeof("svn:date"):
109109
if (constcmp(key, "svn:date"))
110110
break;
111111
if (!val)
112112
die("invalid dump: unsets svn:date");
113-
if (parse_date_basic(val, &rev_ctx.timestamp, NULL))
114-
warning("invalid timestamp: %s", val);
113+
if (parse_date_basic(val->buf, &rev_ctx.timestamp, NULL))
114+
warning("invalid timestamp: %s", val->buf);
115115
break;
116116
case sizeof("svn:executable"):
117117
case sizeof("svn:special"):
@@ -187,10 +187,10 @@ static void read_props(void)
187187
strbuf_swap(&key, &val);
188188
continue;
189189
case 'D':
190-
handle_property(&val, NULL, 0, &type_set);
190+
handle_property(&val, NULL, &type_set);
191191
continue;
192192
case 'V':
193-
handle_property(&key, val.buf, len, &type_set);
193+
handle_property(&key, &val, &type_set);
194194
strbuf_reset(&key);
195195
continue;
196196
default:

0 commit comments

Comments
 (0)