@matheusbsbs / matheus-bagliano / commits / 4c3169b03e
Fork 0

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>

Jonathan Nieder committed Mar 24, 2011 at 23:10 UTC 4c3169b03ec567ac43edcfc08ffdab119e0ebe94
1 file changed +10 -10
vcs-svn/svndump.c
+10 -10
@@ -83,7 +83,7 @@ static void reset_dump_ctx(const char *url)
83 }
84
85 static void handle_property(const struct strbuf *key_buf,
86 - const char *val, uint32_t len,
86 + struct strbuf *val,
87 uint32_t *type_set)
88 {
89 const char *key = key_buf->buf;
@@ -95,23 +95,23 @@ static void handle_property(const struct strbuf *key_buf,
95 break;
96 if (!val)
97 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);
99 break;
100 case sizeof("svn:author"):
101 if (constcmp(key, "svn:author"))
102 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);
107 break;
108 case sizeof("svn:date"):
109 if (constcmp(key, "svn:date"))
110 break;
111 if (!val)
112 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);
115 break;
116 case sizeof("svn:executable"):
117 case sizeof("svn:special"):
@@ -187,10 +187,10 @@ static void read_props(void)
187 strbuf_swap(&key, &val);
188 continue;
189 case 'D':
190 - handle_property(&val, NULL, 0, &type_set);
190 + handle_property(&val, NULL, &type_set);
191 continue;
192 case 'V':
193 - handle_property(&key, val.buf, len, &type_set);
193 + handle_property(&key, &val, &type_set);
194 strbuf_reset(&key);
195 continue;
196 default: