Commit fa54a9c
[ruby/erb] html_escape: Avoid buffer allocation for strings with no
escapable character
(ruby/erb#87)
This change improves reduces allocations and makes `html_escape` ~35% faster in
a benchmark with escaped strings taken from the `test_html_escape` test in
`test/test_erb.rb`.
- Perform buffer allocation on first instance of escapable character.
- Instead of copying characters one at a time, copy unescaped segments using
`memcpy`.
ruby/erb@aa482890fe1 parent 89dc79e commit fa54a9c
1 file changed
+21
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
51 | 62 | | |
52 | 63 | | |
53 | 64 | | |
54 | | - | |
55 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
56 | 71 | | |
57 | 72 | | |
58 | 73 | | |
59 | 74 | | |
60 | | - | |
| 75 | + | |
61 | 76 | | |
62 | 77 | | |
| 78 | + | |
63 | 79 | | |
64 | | - | |
65 | 80 | | |
66 | 81 | | |
67 | 82 | | |
| |||
0 commit comments