From 205ab8a3fe8d7feaedea67d44f09d8ac6af59fd8 Mon Sep 17 00:00:00 2001 From: 1911860538 Date: Mon, 21 Oct 2024 16:27:03 +0000 Subject: html: use sync.OnceValues instead of var once sync.Once Simplify populateMaps with sync.OnceValues. Change-Id: Id52e6e1623c621b8d51e11fecbe3f1fab1e74eb4 GitHub-Last-Rev: 3cf736ae299f14ece401d218d68c3c8870e0cf5a GitHub-Pull-Request: golang/go#69946 Reviewed-on: https://go-review.googlesource.com/c/go/+/621255 Reviewed-by: Michael Pratt Auto-Submit: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor Commit-Queue: Ian Lance Taylor --- src/html/entity.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/html/entity.go') diff --git a/src/html/entity.go b/src/html/entity.go index f0f9a6a973..421a54ab57 100644 --- a/src/html/entity.go +++ b/src/html/entity.go @@ -9,22 +9,16 @@ import "sync" // All entities that do not end with ';' are 6 or fewer bytes long. const longestEntityWithoutSemicolon = 6 +// entityMaps returns entity and entity2. +// // entity is a map from HTML entity names to their values. The semicolon matters: // https://html.spec.whatwg.org/multipage/named-characters.html // lists both "amp" and "amp;" as two separate entries. -// // Note that the HTML5 list is larger than the HTML4 list at // http://www.w3.org/TR/html4/sgml/entities.html -var entity map[string]rune - -// HTML entities that are two unicode codepoints. -var entity2 map[string][2]rune - -// populateMapsOnce guards calling populateMaps. -var populateMapsOnce sync.Once - -// populateMaps populates entity and entity2. -func populateMaps() { +// +// entity2 is a map of HTML entities to two unicode codepoints. +var entityMaps = sync.OnceValues(func() (entity map[string]rune, entity2 map[string][2]rune) { entity = map[string]rune{ "AElig;": '\U000000C6', "AMP;": '\U00000026', @@ -2262,4 +2256,6 @@ func populateMaps() { "vsupnE;": {'\u2ACC', '\uFE00'}, "vsupne;": {'\u228B', '\uFE00'}, } -} + + return entity, entity2 +}) -- cgit v1.3