aboutsummaryrefslogtreecommitdiff
path: root/src/html/entity.go
diff options
context:
space:
mode:
author1911860538 <alxps1911@gmail.com>2024-10-21 16:27:03 +0000
committerGopher Robot <gobot@golang.org>2024-10-21 18:46:08 +0000
commit205ab8a3fe8d7feaedea67d44f09d8ac6af59fd8 (patch)
tree02c3472180c5bbbc134c4a2df88e06783a3587a7 /src/html/entity.go
parent2e9ed44d3943164636271f3242b21f0072b6caa7 (diff)
downloadgo-205ab8a3fe8d7feaedea67d44f09d8ac6af59fd8.tar.xz
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 <mpratt@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/html/entity.go')
-rw-r--r--src/html/entity.go20
1 files changed, 8 insertions, 12 deletions
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
+})