[tor-commits] [tor/release-0.3.1] Improve fragile-hardening performance of consensus_split_lines.
nickm at torproject.org
nickm at torproject.org
Thu Jan 18 13:14:54 UTC 2018
commit 4bb831e0873e7e4468a44dbf9e253bcd5df18421
Author: Nick Mathewson <nickm at torproject.org>
Date: Tue Jan 16 12:42:40 2018 -0500
Improve fragile-hardening performance of consensus_split_lines.
For whatever reason, in my testing, using memchr() here improves
performance over strchr() by a great deal.
Fixes bug 24826; bugfix on 0.3.1.1-alpha.
---
changes/bug24826_031 | 4 ++++
src/or/consdiff.c | 5 ++++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/changes/bug24826_031 b/changes/bug24826_031
new file mode 100644
index 000000000..3d4a66184
--- /dev/null
+++ b/changes/bug24826_031
@@ -0,0 +1,4 @@
+ o Minor bugfixes (performance, fragile-hardening):
+ - Improve the performance of our consensus-diff application code when Tor
+ is built with the --enable-fragile-hardening option set. Fixes bug
+ 24826; bugfix on 0.3.1.1-alpha.
diff --git a/src/or/consdiff.c b/src/or/consdiff.c
index 1baa11897..deaf465fe 100644
--- a/src/or/consdiff.c
+++ b/src/or/consdiff.c
@@ -1285,8 +1285,11 @@ consdiff_apply_diff(const smartlist_t *cons1,
STATIC int
consensus_split_lines(smartlist_t *out, const char *s, memarea_t *area)
{
+ const char *end_of_str = s + strlen(s);
+ tor_assert(*end_of_str == '\0');
+
while (*s) {
- const char *eol = strchr(s, '\n');
+ const char *eol = memchr(s, '\n', end_of_str - s);
if (!eol) {
/* File doesn't end with newline. */
return -1;
More information about the tor-commits
mailing list