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 <jrnieder@gmail.com>
This commit is contained in:
parent
7e2fe3a9fc
commit
4c3169b03e
@ -83,7 +83,7 @@ static void reset_dump_ctx(const char *url)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void handle_property(const struct strbuf *key_buf,
|
static void handle_property(const struct strbuf *key_buf,
|
||||||
const char *val, uint32_t len,
|
struct strbuf *val,
|
||||||
uint32_t *type_set)
|
uint32_t *type_set)
|
||||||
{
|
{
|
||||||
const char *key = key_buf->buf;
|
const char *key = key_buf->buf;
|
||||||
@ -95,23 +95,23 @@ static void handle_property(const struct strbuf *key_buf,
|
|||||||
break;
|
break;
|
||||||
if (!val)
|
if (!val)
|
||||||
die("invalid dump: unsets svn:log");
|
die("invalid dump: unsets svn:log");
|
||||||
strbuf_reset(&rev_ctx.log);
|
strbuf_swap(&rev_ctx.log, val);
|
||||||
strbuf_add(&rev_ctx.log, val, len);
|
|
||||||
break;
|
break;
|
||||||
case sizeof("svn:author"):
|
case sizeof("svn:author"):
|
||||||
if (constcmp(key, "svn:author"))
|
if (constcmp(key, "svn:author"))
|
||||||
break;
|
break;
|
||||||
strbuf_reset(&rev_ctx.author);
|
if (!val)
|
||||||
if (val)
|
strbuf_reset(&rev_ctx.author);
|
||||||
strbuf_add(&rev_ctx.author, val, len);
|
else
|
||||||
|
strbuf_swap(&rev_ctx.author, val);
|
||||||
break;
|
break;
|
||||||
case sizeof("svn:date"):
|
case sizeof("svn:date"):
|
||||||
if (constcmp(key, "svn:date"))
|
if (constcmp(key, "svn:date"))
|
||||||
break;
|
break;
|
||||||
if (!val)
|
if (!val)
|
||||||
die("invalid dump: unsets svn:date");
|
die("invalid dump: unsets svn:date");
|
||||||
if (parse_date_basic(val, &rev_ctx.timestamp, NULL))
|
if (parse_date_basic(val->buf, &rev_ctx.timestamp, NULL))
|
||||||
warning("invalid timestamp: %s", val);
|
warning("invalid timestamp: %s", val->buf);
|
||||||
break;
|
break;
|
||||||
case sizeof("svn:executable"):
|
case sizeof("svn:executable"):
|
||||||
case sizeof("svn:special"):
|
case sizeof("svn:special"):
|
||||||
@ -187,10 +187,10 @@ static void read_props(void)
|
|||||||
strbuf_swap(&key, &val);
|
strbuf_swap(&key, &val);
|
||||||
continue;
|
continue;
|
||||||
case 'D':
|
case 'D':
|
||||||
handle_property(&val, NULL, 0, &type_set);
|
handle_property(&val, NULL, &type_set);
|
||||||
continue;
|
continue;
|
||||||
case 'V':
|
case 'V':
|
||||||
handle_property(&key, val.buf, len, &type_set);
|
handle_property(&key, &val, &type_set);
|
||||||
strbuf_reset(&key);
|
strbuf_reset(&key);
|
||||||
continue;
|
continue;
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user