diff options
| author | Shulhan <ms@kilabit.info> | 2022-07-16 00:45:03 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-07-16 00:45:03 +0700 |
| commit | ed423cf79bd015de79a63b112188a1d79b5c7fb2 (patch) | |
| tree | 79b4daf83e735cd045175705c07d6e8a128f2ec0 | |
| parent | 2e12fb11e048a3a0b247ec50028bb408f229db6b (diff) | |
| download | asciidoctor-go-ed423cf79bd015de79a63b112188a1d79b5c7fb2.tar.xz | |
all: realign all structs
Minimize struct allocation,
* columnFormat: from 40 to 16 bytes (-24 bytes)
* document: from 400 to 392 bytes (-8 bytes)
* element: from 312 to 264 bytes (-48 bytes)
* elementAttribute: from 80 to 72 bytes (-8 bytes)
* elementInclude: from 128 to 120 bytes (-8 bytes)
* elementTable: from 88 to 64 bytes (-24 bytes)
* inlineParser: from 64 to 40 bytes (-24 bytes)
Plus all structs in the test files.
| -rw-r--r-- | cell_format_test.go | 2 | ||||
| -rw-r--r-- | column_format.go | 7 | ||||
| -rw-r--r-- | column_format_test.go | 2 | ||||
| -rw-r--r-- | document.go | 49 | ||||
| -rw-r--r-- | document_parser_test.go | 2 | ||||
| -rw-r--r-- | document_title.go | 6 | ||||
| -rw-r--r-- | element.go | 41 | ||||
| -rw-r--r-- | element_attribute.go | 13 | ||||
| -rw-r--r-- | element_include.go | 2 | ||||
| -rw-r--r-- | element_table.go | 13 | ||||
| -rw-r--r-- | element_table_test.go | 2 | ||||
| -rw-r--r-- | element_test.go | 2 | ||||
| -rw-r--r-- | inline_parser.go | 20 | ||||
| -rw-r--r-- | parser_paragraph_test.go | 2 | ||||
| -rw-r--r-- | section_counters_test.go | 2 | ||||
| -rw-r--r-- | testdata/got.test.html | 2 |
16 files changed, 93 insertions, 74 deletions
diff --git a/cell_format_test.go b/cell_format_test.go index ca5337f..58ef097 100644 --- a/cell_format_test.go +++ b/cell_format_test.go @@ -11,8 +11,8 @@ import ( func TestParseCellFormat(t *testing.T) { cases := []struct { - raw string exp *cellFormat + raw string }{{ raw: "3*", exp: &cellFormat{ diff --git a/column_format.go b/column_format.go index 2f667f7..aca4849 100644 --- a/column_format.go +++ b/column_format.go @@ -38,14 +38,17 @@ var _colStyles = map[byte]int{ } type columnFormat struct { + width *big.Rat + + classes []string + alignHor int alignVer int style int - width *big.Rat - classes []string // isDefault will true if its contains '*'. isDefault bool + // isAutowidth will true if its contains '~'. isAutowidth bool } diff --git a/column_format_test.go b/column_format_test.go index e091fd9..dff9280 100644 --- a/column_format_test.go +++ b/column_format_test.go @@ -12,9 +12,9 @@ import ( func TestParseColumnFormat(t *testing.T) { cases := []struct { + expFormat *columnFormat s string expNCols int - expFormat *columnFormat }{{ s: "3*", expNCols: 3, diff --git a/document.go b/document.go index b3ab500..cdab21e 100644 --- a/document.go +++ b/document.go @@ -24,42 +24,45 @@ const ( // Document represent content of asciidoc that has been parsed. type Document struct { - Title DocumentTitle - Authors []*Author - Revision Revision - LastUpdated string - Attributes AttributeEntry - TOCLevel int + // anchors contains mapping between unique ID and its label. + anchors map[string]*anchor - rawAuthors string - rawRevision string - tocClasses attributeClass - tocPosition string - tocTitle string - tocIsEnabled bool + content *element + header *element - file string - fpath string - classes attributeClass + Attributes AttributeEntry + sectnums *sectionCounters - // anchors contains mapping between unique ID and its label. - anchors map[string]*anchor // titleID is the reverse of anchors, it contains mapping of title and // its ID. titleID map[string]string - sectnums *sectionCounters - sectLevel int + Revision Revision - header *element - content *element + LastUpdated string + file string + fpath string + rawAuthors string + rawRevision string + tocPosition string + tocTitle string + + Title DocumentTitle + classes attributeClass + tocClasses attributeClass + + Authors []*Author + + TOCLevel int + sectLevel int counterExample int counterImage int counterTable int - isEmbedded bool - isForToC bool + isEmbedded bool + isForToC bool + tocIsEnabled bool } func newDocument() *Document { diff --git a/document_parser_test.go b/document_parser_test.go index 30d6794..9cf2623 100644 --- a/document_parser_test.go +++ b/document_parser_test.go @@ -100,8 +100,8 @@ func TestParse_metaShowTitle(t *testing.T) { func TestParse_document_title(t *testing.T) { cases := []struct { content string - exp DocumentTitle expString string + exp DocumentTitle }{{ content: `= Main: sub`, exp: DocumentTitle{ diff --git a/document_title.go b/document_title.go index d4ce06a..e646a8a 100644 --- a/document_title.go +++ b/document_title.go @@ -6,11 +6,13 @@ package asciidoctor import "fmt" type DocumentTitle struct { + el *element + Main string Sub string - el *element raw string - sep byte + + sep byte } // String return the combination of main and subtitle separated by colon or @@ -15,33 +15,36 @@ import ( // element is the building block of asciidoc document. type element struct { - elementAttribute - - Text string // The content of element without inline formatting. - kind int - level int // The number of dot for ordered list, or '*' for unordered list. - raw []byte // unparsed content of element. - rawLabel bytes.Buffer - rawTitle string - - // The key and value for attribute (lineKindAttribute). - key string - value string - // title is the parsed rawTitle for section L1 or parsed raw for // section L2-L5. title *element - label *element + + prev *element + next *element + parent *element + child *element + label *element + + table *elementTable // sectnums contain the current section numbers. // It will be set only if attribute "sectnums" is on. sectnums *sectionCounters - table *elementTable - parent *element - child *element - next *element - prev *element + // The key and value for attribute (lineKindAttribute). + key string + value string + + rawTitle string + Text string // The content of element without inline formatting. + + raw []byte // Unparsed content of element. + + elementAttribute + + rawLabel bytes.Buffer + level int // The number of dot for ordered list, or '*' for unordered list. + kind int } func (el *element) getListOrderedClass() string { diff --git a/element_attribute.go b/element_attribute.go index ec24b9d..6f2f5af 100644 --- a/element_attribute.go +++ b/element_attribute.go @@ -11,13 +11,16 @@ import ( ) type elementAttribute struct { + Attrs map[string]string + ID string - Attrs map[string]string - style int64 rawStyle string - roles []string - options []string - pos int + + roles []string + options []string + + style int64 + pos int } func (ea *elementAttribute) addRole(role string) { diff --git a/element_include.go b/element_include.go index 3a6a689..711ae29 100644 --- a/element_include.go +++ b/element_include.go @@ -12,8 +12,8 @@ import ( type elementInclude struct { fpath string - attrs elementAttribute content []byte + attrs elementAttribute } func parseInclude(doc *Document, line []byte) (el *elementInclude) { diff --git a/element_table.go b/element_table.go index 1378f02..fcd7af5 100644 --- a/element_table.go +++ b/element_table.go @@ -13,11 +13,14 @@ import ( ) type elementTable struct { - ncols int - rows []*tableRow - formats []*columnFormat - classes attributeClass - styles map[string]string + styles map[string]string + + rows []*tableRow + formats []*columnFormat + + classes attributeClass + ncols int + hasHeader bool hasFooter bool } diff --git a/element_table_test.go b/element_table_test.go index 3680358..5a9907e 100644 --- a/element_table_test.go +++ b/element_table_test.go @@ -13,8 +13,8 @@ import ( func TestParseAttrCols(t *testing.T) { cases := []struct { val string - ncols int formats []*columnFormat + ncols int }{{ val: "3*", ncols: 3, diff --git a/element_test.go b/element_test.go index f6bea81..9fe0c01 100644 --- a/element_test.go +++ b/element_test.go @@ -13,9 +13,9 @@ import ( func TestAdocNode_parseListDescriptionItem(t *testing.T) { cases := []struct { line string - expLevel int expRawTerm string expRaw string + expLevel int }{{ line: "CPU::", expLevel: 0, diff --git a/inline_parser.go b/inline_parser.go index 6a4b5eb..7d79ef3 100644 --- a/inline_parser.go +++ b/inline_parser.go @@ -14,14 +14,18 @@ import ( type inlineParser struct { container *element current *element - content []byte - doc *Document - x int - state *inlineParserState - prev byte - c byte - nextc byte - nextcc byte + + doc *Document + state *inlineParserState + + content []byte + + x int + prev byte + c byte + nextc byte + nextcc byte + isEscaped bool } diff --git a/parser_paragraph_test.go b/parser_paragraph_test.go index 8ca96ac..f87ae3b 100644 --- a/parser_paragraph_test.go +++ b/parser_paragraph_test.go @@ -13,8 +13,8 @@ import ( func TestParser_parseParagraph(t *testing.T) { cases := []struct { desc string - content []byte exp string + content []byte }{{ desc: "with lead style", content: []byte(`[.lead] diff --git a/section_counters_test.go b/section_counters_test.go index b6b5958..5020083 100644 --- a/section_counters_test.go +++ b/section_counters_test.go @@ -13,9 +13,9 @@ func TestSectionCounters(t *testing.T) { sec := §ionCounters{} cases := []struct { - level int exp *sectionCounters expString string + level int }{{ level: 2, exp: §ionCounters{ diff --git a/testdata/got.test.html b/testdata/got.test.html index 3c3e599..704ee70 100644 --- a/testdata/got.test.html +++ b/testdata/got.test.html @@ -2332,9 +2332,7 @@ D</p></td> package asciidoctor -// // anchor contains label and counter for duplicate ID. -// type anchor struct { label string counter int |
