mirror of
https://github.com/golang/go
synced 2024-11-12 10:20:27 -07:00
html: lazily populate Unescape tables
Saves ~105KB of heap for callers who don't use html.UnescapeString. (EscapeString is much more common). Also saves 70KB of binary size, because now the linker can do dead code elimination. (because #2559 is still open and global maps always generate init code) Fixes #26727 Updates #6853 Change-Id: I18fe9a273097e2c7e0cb7f88205cae1bb60fa89b Reviewed-on: https://go-review.googlesource.com/127075 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
04c095886f
commit
740e589bd0
4482
src/html/entity.go
4482
src/html/entity.go
File diff suppressed because it is too large
Load Diff
@ -9,7 +9,15 @@ import (
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func init() {
|
||||
UnescapeString("") // force load of entity maps
|
||||
}
|
||||
|
||||
func TestEntityLength(t *testing.T) {
|
||||
if len(entity) == 0 || len(entity2) == 0 {
|
||||
t.Fatal("maps not loaded")
|
||||
}
|
||||
|
||||
// We verify that the length of UTF-8 encoding of each value is <= 1 + len(key).
|
||||
// The +1 comes from the leading "&". This property implies that the length of
|
||||
// unescaped text is <= the length of escaped text.
|
||||
|
@ -185,6 +185,7 @@ func EscapeString(s string) string {
|
||||
// UnescapeString(EscapeString(s)) == s always holds, but the converse isn't
|
||||
// always true.
|
||||
func UnescapeString(s string) string {
|
||||
populateMapsOnce.Do(populateMaps)
|
||||
i := strings.IndexByte(s, '&')
|
||||
|
||||
if i < 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user