• Didier Spezia's avatar
    html: simplify and optimize escape/unescape · 2d9a50b9
    Didier Spezia authored
    The html package uses some specific code to escape special characters.
    Actually, the strings.Replacer can be used instead, and is much more
    efficient. The converse operation is more complex but can still be
    slightly optimized.
    
    Credits to Ken Bloom (kabloom@google.com), who first submitted a
    similar patch at https://codereview.appspot.com/141930043
    
    Added benchmarks and slightly optimized UnescapeString.
    
    benchmark                   old ns/op     new ns/op     delta
    BenchmarkEscape-4           118713        19825         -83.30%
    BenchmarkEscapeNone-4       87653         3784          -95.68%
    BenchmarkUnescape-4         24888         23417         -5.91%
    BenchmarkUnescapeNone-4     14423         157           -98.91%
    
    benchmark                   old allocs     new allocs     delta
    BenchmarkEscape-4           9              2              -77.78%
    BenchmarkEscapeNone-4       0              0              +0.00%
    BenchmarkUnescape-4         2              2              +0.00%
    BenchmarkUnescapeNone-4     0              0              +0.00%
    
    benchmark                   old bytes     new bytes     delta
    BenchmarkEscape-4           24800         12288         -50.45%
    BenchmarkEscapeNone-4       0             0             +0.00%
    BenchmarkUnescape-4         10240         10240         +0.00%
    BenchmarkUnescapeNone-4     0             0             +0.00%
    
    Fixes #8697
    
    Change-Id: I208261ed7cbe9b3dee6317851f8c0cf15528bce4
    Reviewed-on: https://go-review.googlesource.com/9808
    Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
    Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    2d9a50b9
Name
Last commit
Last update
..
archive Loading commit data...
bufio Loading commit data...
builtin Loading commit data...
bytes Loading commit data...
cmd Loading commit data...
compress Loading commit data...
container Loading commit data...
crypto Loading commit data...
database/sql Loading commit data...
debug Loading commit data...
encoding Loading commit data...
errors Loading commit data...
expvar Loading commit data...
flag Loading commit data...
fmt Loading commit data...
go Loading commit data...
hash Loading commit data...
html Loading commit data...
image Loading commit data...
index/suffixarray Loading commit data...
internal Loading commit data...
io Loading commit data...
log Loading commit data...
math Loading commit data...
mime Loading commit data...
net Loading commit data...
os Loading commit data...
path Loading commit data...
reflect Loading commit data...
regexp Loading commit data...
runtime Loading commit data...
sort Loading commit data...
strconv Loading commit data...
strings Loading commit data...
sync Loading commit data...
syscall Loading commit data...
testing Loading commit data...
text Loading commit data...
time Loading commit data...
unicode Loading commit data...
unsafe Loading commit data...
Make.dist Loading commit data...
all.bash Loading commit data...
all.bat Loading commit data...
all.rc Loading commit data...
androidtest.bash Loading commit data...
bootstrap.bash Loading commit data...
buildall.bash Loading commit data...
clean.bash Loading commit data...
clean.bat Loading commit data...
clean.rc Loading commit data...
iostest.bash Loading commit data...
make.bash Loading commit data...
make.bat Loading commit data...
make.rc Loading commit data...
nacltest.bash Loading commit data...
race.bash Loading commit data...
race.bat Loading commit data...
run.bash Loading commit data...
run.bat Loading commit data...
run.rc Loading commit data...