// Cache for page listings.
cachePages *dynacache.Partition[string, page.Pages]
// Cache for content sources.
- cacheContentSource *dynacache.Partition[string, *resources.StaleValue[[]byte]]
+ cacheContentSource *dynacache.Partition[uint64, *resources.StaleValue[[]byte]]
// Before Hugo 0.122.0 we managed all translations in a map using a translationKey
// that could be overridden in front matter.
"fmt"
"html/template"
"io"
- "strconv"
"strings"
"sync/atomic"
"unicode/utf8"
h *HugoSites,
sid uint64,
) error {
- var sourceKey string
-
- if sourceKey == "" {
- sourceKey = strconv.FormatUint(sid, 10)
- }
-
var filename string
if m.f != nil {
filename = m.f.Filename()
m.pi = &contentParseInfo{
h: h,
sid: sid,
- sourceKey: sourceKey,
openSource: m.openSource,
shortcodeParseInfo: newShortcodeHandler(filename, h.Deps),
}
type contentParseInfo struct {
h *HugoSites
- sid uint64
- sourceKey string
+ sid uint64
// The source bytes.
openSource hugio.OpenReadSeekCloser
currShortcode.pos = it.Pos()
currShortcode.length = iter.Current().Pos() - it.Pos()
if currShortcode.placeholder == "" {
- currShortcode.placeholder = createShortcodePlaceholder("s", pi.sid, currShortcode.ordinal)
+ currShortcode.placeholder = createShortcodePlaceholder("s", pi.sid, uint64(currShortcode.ordinal))
}
if currShortcode.name != "" {
currShortcode.params = s
}
- currShortcode.placeholder = createShortcodePlaceholder("s", pi.sid, ordinal)
+ currShortcode.placeholder = createShortcodePlaceholder("s", pi.sid, uint64(ordinal))
ordinal++
s.shortcodes = append(s.shortcodes, currShortcode)
}
func (pi *contentParseInfo) contentSource(s resource.StaleInfo) ([]byte, error) {
- key := pi.sourceKey
+ key := pi.sid
versionv := s.StaleVersion()
- v, err := pi.h.cacheContentSource.GetOrCreate(key, func(string) (*resources.StaleValue[[]byte], error) {
+ v, err := pi.h.cacheContentSource.GetOrCreate(key, func(uint64) (*resources.StaleValue[[]byte], error) {
b, err := pi.readSourceAll()
if err != nil {
return nil, err
}
func (c *cachedContentScope) keyScope(ctx context.Context) string {
- return hugo.GetMarkupScope(ctx) + c.pco.po.f.Name
+ return hugo.GetMarkupScope(ctx) + c.pco.po.f.Name + fmt.Sprintf("_%d", c.pi.sid)
}
func (c *cachedContentScope) contentRendered(ctx context.Context) (contentSummary, error) {
cp := c.pco
ctx = tpl.Context.DependencyScope.Set(ctx, pageDependencyScopeGlobal)
- key := c.pi.sourceKey + "/" + c.keyScope(ctx)
+ key := c.keyScope(ctx)
versionv := c.version(cp)
func (c *cachedContentScope) contentToC(ctx context.Context) (contentTableOfContents, error) {
cp := c.pco
- key := c.pi.sourceKey + "/" + c.keyScope(ctx)
+ key := c.keyScope(ctx)
versionv := c.version(cp)
v, err := c.pm.contentTableOfContents.GetOrCreate(key, func(string) (*resources.StaleValue[contentTableOfContents], error) {
func (c *cachedContentScope) contentPlain(ctx context.Context) (contentPlainPlainWords, error) {
cp := c.pco
- key := c.pi.sourceKey + "/" + c.keyScope(ctx)
+ key := c.keyScope(ctx)
versionv := c.version(cp)
// Note - this value must not contain any markup syntax
const shortcodePlaceholderPrefix = "HAHAHUGOSHORTCODE"
-func createShortcodePlaceholder(sid string, id uint64, ordinal int) string {
- return shortcodePlaceholderPrefix + strconv.FormatUint(id, 10) + sid + strconv.Itoa(ordinal) + "HBHB"
+func createShortcodePlaceholder(sid string, id, ordinal uint64) string {
+ return shortcodePlaceholderPrefix + strconv.FormatUint(id, 10) + sid + strconv.FormatUint(ordinal, 10) + "HBHB"
}
type shortcode struct {
--- /dev/null
+// Copyright 2025 The Hugo Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package hugolib
+
+import "testing"
+
+func BenchmarkCreateShortcodePlaceholders(b *testing.B) {
+ var ordinal int = 42
+ for b.Loop() {
+ createShortcodePlaceholder("shortcodeName", 32, uint64(ordinal))
+ }
+}
page.Pages](d.MemCache, "/pags/all",
dynacache.OptionsPartition{Weight: 10, ClearWhen: dynacache.ClearOnRebuild},
),
- cacheContentSource: dynacache.GetOrCreatePartition[string, *resources.StaleValue[[]byte]](d.MemCache, "/cont/src", dynacache.OptionsPartition{Weight: 70, ClearWhen: dynacache.ClearOnChange}),
+ cacheContentSource: dynacache.GetOrCreatePartition[uint64, *resources.StaleValue[[]byte]](d.MemCache, "/cont/src", dynacache.OptionsPartition{Weight: 70, ClearWhen: dynacache.ClearOnChange}),
translationKeyPages: maps.NewSliceCache[page.Page](),
currentSite: first[0],
skipRebuildForFilenames: make(map[string]bool),
}
})
- b.Run("HasAnyVector", func(b *testing.B) {
+ b.Run("HasAnyVector(Sets)", func(b *testing.B) {
for b.Loop() {
_ = sets1.HasAnyVector(sets2)
}
})
+ b.Run("HasAnyVector(Vector)", func(b *testing.B) {
+ for b.Loop() {
+ _ = sets1.HasAnyVector(v1)
+ }
+ })
+
+ b.Run("HasAnyVector(&Vector)", func(b *testing.B) {
+ for b.Loop() {
+ _ = sets1.HasAnyVector(&v1)
+ }
+ })
b.Run("FirstVector", func(b *testing.B) {
for b.Loop() {