folly: toLowerAscii: avoid unaligned access; also correct 3 conditions
authorJim Meyering <meyering@fb.com>
Mon, 14 Jul 2014 23:21:07 +0000 (16:21 -0700)
committerTudor Bosman <tudorb@fb.com>
Mon, 21 Jul 2014 19:22:03 +0000 (12:22 -0700)
commit24e54548c4bdbcd78f5155026ca08b5dbb78b48d
tree4a3b40cc8609575433e1610ef8e89314ede36325
parentb003d618a0521f5282ac7832ac465fe2931065ff
folly: toLowerAscii: avoid unaligned access; also correct 3 conditions

Summary:
* folly/String.cpp (toLowerAscii): Fix two errors: the most important
would cause unaligned accesses.  This would cause a performance loss
in general, but would also result in segfaults on ARM processes.
In addition, three conditionals were wrong, further limiting
the performance of this code: switch those "<" to "<=".

Test Plan:
Run this to exercise existing tests:
fbconfig folly/test:string_test && fbmake runtests_opt
Run this to generate timing stats (before and after this change), e.g.,
fbconfig folly/test:string_benchmark && fbmake opt
_bin/folly/test/string_benchmark > TIMING-toLower-old

These numbers show a 1.6% speed increase with this change:

--- TIMING-toLower-old  2014-07-14 16:51:12.793523778 -0700
+++ TIMING-toLower-new  2014-07-14 16:49:45.815119145 -0700
@@ -1,6 +1,6 @@
============================================================================
folly/test/StringBenchmark.cpp                  relative  time/iter  iters/s
============================================================================
-libc_tolower                                                 1.06us  941.91K
-folly_toLowerAscii                                          89.99ns   11.11M
+libc_tolower                                                 1.06us  941.90K
+folly_toLowerAscii                                          88.57ns   11.29M
============================================================================

Reviewed By: brianp@fb.com

Subscribers:

FB internal diff: D1434585

Tasks: 4696800

Blame Revision: D1421056
folly/String.cpp