diff options
author | Bjørn Erik Pedersen <[email protected]> | 2022-07-07 16:11:47 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2022-07-09 16:03:11 +0200 |
commit | 223bf2800488ad5d38854bbb595d789bc35ebe32 (patch) | |
tree | 84b04f8f50b4450cf5f87943befe31fd9d7b8b90 /hugolib/shortcode.go | |
parent | 72b0ccdb010fcdfeb3bb4a955d4fc04529816c0d (diff) | |
download | hugo-223bf2800488ad5d38854bbb595d789bc35ebe32.tar.gz hugo-223bf2800488ad5d38854bbb595d789bc35ebe32.zip |
parser/pageparser: Don't store the byte slices
On its own this change doesn't do any magic, but this is part of a bigger picture about making Hugo leaner in the
memory usage department.
Diffstat (limited to 'hugolib/shortcode.go')
-rw-r--r-- | hugolib/shortcode.go | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go index 33767fc68..1627acacb 100644 --- a/hugolib/shortcode.go +++ b/hugolib/shortcode.go @@ -509,7 +509,7 @@ func (s *shortcodeHandler) parseError(err error, input []byte, pos int) error { // pageTokens state: // - before: positioned just before the shortcode start // - after: shortcode(s) consumed (plural when they are nested) -func (s *shortcodeHandler) extractShortcode(ordinal, level int, pt *pageparser.Iterator) (*shortcode, error) { +func (s *shortcodeHandler) extractShortcode(ordinal, level int, source []byte, pt *pageparser.Iterator) (*shortcode, error) { if s == nil { panic("handler nil") } @@ -520,7 +520,7 @@ func (s *shortcodeHandler) extractShortcode(ordinal, level int, pt *pageparser.I pt.Backup() item := pt.Next() if item.IsIndentation() { - sc.indentation = string(item.Val) + sc.indentation = item.ValStr(source) } } @@ -530,7 +530,7 @@ func (s *shortcodeHandler) extractShortcode(ordinal, level int, pt *pageparser.I const errorPrefix = "failed to extract shortcode" fail := func(err error, i pageparser.Item) error { - return s.parseError(fmt.Errorf("%s: %w", errorPrefix, err), pt.Input(), i.Pos) + return s.parseError(fmt.Errorf("%s: %w", errorPrefix, err), source, i.Pos()) } Loop: @@ -550,7 +550,7 @@ Loop: if cnt > 0 { // nested shortcode; append it to inner content pt.Backup() - nested, err := s.extractShortcode(nestedOrdinal, nextLevel, pt) + nested, err := s.extractShortcode(nestedOrdinal, nextLevel, source, pt) nestedOrdinal++ if nested != nil && nested.name != "" { s.addName(nested.name) @@ -589,7 +589,7 @@ Loop: // return that error, more specific continue } - return sc, fail(fmt.Errorf("shortcode %q has no .Inner, yet a closing tag was provided", next.Val), next) + return sc, fail(fmt.Errorf("shortcode %q has no .Inner, yet a closing tag was provided", next.ValStr(source)), next) } } if next.IsRightShortcodeDelim() { @@ -602,11 +602,11 @@ Loop: return sc, nil case currItem.IsText(): - sc.inner = append(sc.inner, currItem.ValStr()) + sc.inner = append(sc.inner, currItem.ValStr(source)) case currItem.Type == pageparser.TypeEmoji: // TODO(bep) avoid the duplication of these "text cases", to prevent // more of #6504 in the future. - val := currItem.ValStr() + val := currItem.ValStr(source) if emoji := helpers.Emoji(val); emoji != nil { sc.inner = append(sc.inner, string(emoji)) } else { @@ -614,7 +614,7 @@ Loop: } case currItem.IsShortcodeName(): - sc.name = currItem.ValStr() + sc.name = currItem.ValStr(source) // Used to check if the template expects inner content. templs := s.s.Tmpl().LookupVariants(sc.name) @@ -625,7 +625,7 @@ Loop: sc.info = templs[0].(tpl.Info) sc.templs = templs case currItem.IsInlineShortcodeName(): - sc.name = currItem.ValStr() + sc.name = currItem.ValStr(source) sc.isInline = true case currItem.IsShortcodeParam(): if !pt.IsValueNext() { @@ -634,11 +634,11 @@ Loop: // named params if sc.params == nil { params := make(map[string]any) - params[currItem.ValStr()] = pt.Next().ValTyped() + params[currItem.ValStr(source)] = pt.Next().ValTyped(source) sc.params = params } else { if params, ok := sc.params.(map[string]any); ok { - params[currItem.ValStr()] = pt.Next().ValTyped() + params[currItem.ValStr(source)] = pt.Next().ValTyped(source) } else { return sc, errShortCodeIllegalState } @@ -647,11 +647,11 @@ Loop: // positional params if sc.params == nil { var params []any - params = append(params, currItem.ValTyped()) + params = append(params, currItem.ValTyped(source)) sc.params = params } else { if params, ok := sc.params.([]any); ok { - params = append(params, currItem.ValTyped()) + params = append(params, currItem.ValTyped(source)) sc.params = params } else { return sc, errShortCodeIllegalState |