Commit 90fa13d2 authored by Nigel Tao's avatar Nigel Tao

exp/html/atom: add more atoms.

This completely covers the tags used by exp/html's parser.

Before:
295 atoms; 1406 string bytes + 2048 tables = 3454 total data
BenchmarkLookup    50000         59841 ns/op

After:
322 atoms; 1508 string bytes + 2048 tables = 3556 total data
BenchmarkLookup    50000         60159 ns/op

R=r
CC=golang-dev
https://golang.org/cl/6296045
parent 55282111
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Package atom provides integer codes (also known as atoms) for a fixed set of // Package atom provides integer codes (also known as atoms) for a fixed set of
// frequently occurring HTML strings: lower-case tag names and attribute keys // frequently occurring HTML strings: tag names and attribute keys such as "p"
// such as "p" and "id". // and "id".
// //
// Sharing an atom's name between all elements with the same tag can result in // Sharing an atom's name between all elements with the same tag can result in
// fewer string allocations when tokenizing and parsing HTML. Integer // fewer string allocations when tokenizing and parsing HTML. Integer
...@@ -56,7 +56,7 @@ func match(s string, t []byte) bool { ...@@ -56,7 +56,7 @@ func match(s string, t []byte) bool {
} }
// Lookup returns the atom whose name is s. It returns zero if there is no // Lookup returns the atom whose name is s. It returns zero if there is no
// such atom. // such atom. The lookup is case sensitive.
func Lookup(s []byte) Atom { func Lookup(s []byte) Atom {
if len(s) == 0 || len(s) > maxAtomLen { if len(s) == 0 || len(s) > maxAtomLen {
return 0 return 0
......
...@@ -65,6 +65,27 @@ func TestMisses(t *testing.T) { ...@@ -65,6 +65,27 @@ func TestMisses(t *testing.T) {
} }
} }
func TestForeignObject(t *testing.T) {
const (
afo = Foreignobject
afO = ForeignObject
sfo = "foreignobject"
sfO = "foreignObject"
)
if got := Lookup([]byte(sfo)); got != afo {
t.Errorf("Lookup(%q): got %#v, want %#v", sfo, got, afo)
}
if got := Lookup([]byte(sfO)); got != afO {
t.Errorf("Lookup(%q): got %#v, want %#v", sfO, got, afO)
}
if got := afo.String(); got != sfo {
t.Errorf("Atom(%#v).String(): got %q, want %q", afo, got, sfo)
}
if got := afO.String(); got != sfO {
t.Errorf("Atom(%#v).String(): got %q, want %q", afO, got, sfO)
}
}
func BenchmarkLookup(b *testing.B) { func BenchmarkLookup(b *testing.B) {
sortedTable := make([]string, 0, len(table)) sortedTable := make([]string, 0, len(table))
for _, a := range table { for _, a := range table {
......
...@@ -594,11 +594,38 @@ var eventHandlers = []string{ ...@@ -594,11 +594,38 @@ var eventHandlers = []string{
var extra = []string{ var extra = []string{
"align", "align",
"annotation", "annotation",
"annotation-xml",
"applet", "applet",
"basefont",
"bgsound",
"big",
"center", "center",
"color", "color",
"desc",
"face",
"font", "font",
"foreignObject", // HTML is case-insensitive, but SVG-embedded-in-HTML is case-sensitive.
"foreignobject",
"frame", "frame",
"frameset", "frameset",
"image",
"isindex",
"listing",
"malignmark",
"marquee",
"math",
"mglyph",
"mi",
"mn",
"mo",
"ms",
"mtext",
"nobr", "nobr",
"noembed",
"noframes",
"plaintext",
"strike",
"svg",
"tt",
"xmp",
} }
This diff is collapsed.
...@@ -13,6 +13,7 @@ var testAtomList = []string{ ...@@ -13,6 +13,7 @@ var testAtomList = []string{
"align", "align",
"alt", "alt",
"annotation", "annotation",
"annotation-xml",
"applet", "applet",
"area", "area",
"article", "article",
...@@ -24,8 +25,11 @@ var testAtomList = []string{ ...@@ -24,8 +25,11 @@ var testAtomList = []string{
"autoplay", "autoplay",
"b", "b",
"base", "base",
"basefont",
"bdi", "bdi",
"bdo", "bdo",
"bgsound",
"big",
"blockquote", "blockquote",
"body", "body",
"border", "border",
...@@ -62,6 +66,7 @@ var testAtomList = []string{ ...@@ -62,6 +66,7 @@ var testAtomList = []string{
"default", "default",
"defer", "defer",
"del", "del",
"desc",
"details", "details",
"dfn", "dfn",
"dialog", "dialog",
...@@ -77,12 +82,15 @@ var testAtomList = []string{ ...@@ -77,12 +82,15 @@ var testAtomList = []string{
"em", "em",
"embed", "embed",
"enctype", "enctype",
"face",
"fieldset", "fieldset",
"figcaption", "figcaption",
"figure", "figure",
"font", "font",
"footer", "footer",
"for", "for",
"foreignObject",
"foreignobject",
"form", "form",
"form", "form",
"formaction", "formaction",
...@@ -114,10 +122,12 @@ var testAtomList = []string{ ...@@ -114,10 +122,12 @@ var testAtomList = []string{
"icon", "icon",
"id", "id",
"iframe", "iframe",
"image",
"img", "img",
"inert", "inert",
"input", "input",
"ins", "ins",
"isindex",
"ismap", "ismap",
"itemid", "itemid",
"itemprop", "itemprop",
...@@ -135,11 +145,15 @@ var testAtomList = []string{ ...@@ -135,11 +145,15 @@ var testAtomList = []string{
"li", "li",
"link", "link",
"list", "list",
"listing",
"loop", "loop",
"low", "low",
"malignmark",
"manifest", "manifest",
"map", "map",
"mark", "mark",
"marquee",
"math",
"max", "max",
"maxlength", "maxlength",
"media", "media",
...@@ -148,12 +162,20 @@ var testAtomList = []string{ ...@@ -148,12 +162,20 @@ var testAtomList = []string{
"meta", "meta",
"meter", "meter",
"method", "method",
"mglyph",
"mi",
"min", "min",
"mn",
"mo",
"ms",
"mtext",
"multiple", "multiple",
"muted", "muted",
"name", "name",
"nav", "nav",
"nobr", "nobr",
"noembed",
"noframes",
"noscript", "noscript",
"novalidate", "novalidate",
"object", "object",
...@@ -236,6 +258,7 @@ var testAtomList = []string{ ...@@ -236,6 +258,7 @@ var testAtomList = []string{
"pattern", "pattern",
"ping", "ping",
"placeholder", "placeholder",
"plaintext",
"poster", "poster",
"pre", "pre",
"preload", "preload",
...@@ -274,12 +297,14 @@ var testAtomList = []string{ ...@@ -274,12 +297,14 @@ var testAtomList = []string{
"srclang", "srclang",
"start", "start",
"step", "step",
"strike",
"strong", "strong",
"style", "style",
"style", "style",
"sub", "sub",
"summary", "summary",
"sup", "sup",
"svg",
"tabindex", "tabindex",
"table", "table",
"target", "target",
...@@ -295,6 +320,7 @@ var testAtomList = []string{ ...@@ -295,6 +320,7 @@ var testAtomList = []string{
"tr", "tr",
"track", "track",
"translate", "translate",
"tt",
"type", "type",
"typemustmatch", "typemustmatch",
"u", "u",
...@@ -306,4 +332,5 @@ var testAtomList = []string{ ...@@ -306,4 +332,5 @@ var testAtomList = []string{
"wbr", "wbr",
"width", "width",
"wrap", "wrap",
"xmp",
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment