1
0
mirror of https://github.com/golang/go synced 2024-11-21 21:24:45 -07:00

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
This commit is contained in:
Nigel Tao 2012-06-07 09:35:35 +10:00
parent 5528211158
commit 90fa13d2b7
5 changed files with 740 additions and 609 deletions

View File

@ -3,8 +3,8 @@
// license that can be found in the LICENSE file.
// 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
// such as "p" and "id".
// frequently occurring HTML strings: tag names and attribute keys such as "p"
// and "id".
//
// Sharing an atom's name between all elements with the same tag can result in
// fewer string allocations when tokenizing and parsing HTML. Integer
@ -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
// such atom.
// such atom. The lookup is case sensitive.
func Lookup(s []byte) Atom {
if len(s) == 0 || len(s) > maxAtomLen {
return 0

View File

@ -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) {
sortedTable := make([]string, 0, len(table))
for _, a := range table {

View File

@ -594,11 +594,38 @@ var eventHandlers = []string{
var extra = []string{
"align",
"annotation",
"annotation-xml",
"applet",
"basefont",
"bgsound",
"big",
"center",
"color",
"desc",
"face",
"font",
"foreignObject", // HTML is case-insensitive, but SVG-embedded-in-HTML is case-sensitive.
"foreignobject",
"frame",
"frameset",
"image",
"isindex",
"listing",
"malignmark",
"marquee",
"math",
"mglyph",
"mi",
"mn",
"mo",
"ms",
"mtext",
"nobr",
"noembed",
"noframes",
"plaintext",
"strike",
"svg",
"tt",
"xmp",
}

File diff suppressed because it is too large Load Diff

View File

@ -13,6 +13,7 @@ var testAtomList = []string{
"align",
"alt",
"annotation",
"annotation-xml",
"applet",
"area",
"article",
@ -24,8 +25,11 @@ var testAtomList = []string{
"autoplay",
"b",
"base",
"basefont",
"bdi",
"bdo",
"bgsound",
"big",
"blockquote",
"body",
"border",
@ -62,6 +66,7 @@ var testAtomList = []string{
"default",
"defer",
"del",
"desc",
"details",
"dfn",
"dialog",
@ -77,12 +82,15 @@ var testAtomList = []string{
"em",
"embed",
"enctype",
"face",
"fieldset",
"figcaption",
"figure",
"font",
"footer",
"for",
"foreignObject",
"foreignobject",
"form",
"form",
"formaction",
@ -114,10 +122,12 @@ var testAtomList = []string{
"icon",
"id",
"iframe",
"image",
"img",
"inert",
"input",
"ins",
"isindex",
"ismap",
"itemid",
"itemprop",
@ -135,11 +145,15 @@ var testAtomList = []string{
"li",
"link",
"list",
"listing",
"loop",
"low",
"malignmark",
"manifest",
"map",
"mark",
"marquee",
"math",
"max",
"maxlength",
"media",
@ -148,12 +162,20 @@ var testAtomList = []string{
"meta",
"meter",
"method",
"mglyph",
"mi",
"min",
"mn",
"mo",
"ms",
"mtext",
"multiple",
"muted",
"name",
"nav",
"nobr",
"noembed",
"noframes",
"noscript",
"novalidate",
"object",
@ -236,6 +258,7 @@ var testAtomList = []string{
"pattern",
"ping",
"placeholder",
"plaintext",
"poster",
"pre",
"preload",
@ -274,12 +297,14 @@ var testAtomList = []string{
"srclang",
"start",
"step",
"strike",
"strong",
"style",
"style",
"sub",
"summary",
"sup",
"svg",
"tabindex",
"table",
"target",
@ -295,6 +320,7 @@ var testAtomList = []string{
"tr",
"track",
"translate",
"tt",
"type",
"typemustmatch",
"u",
@ -306,4 +332,5 @@ var testAtomList = []string{
"wbr",
"width",
"wrap",
"xmp",
}