all: Replace RWMutex struct caches with ConcurrentMap

This commit is contained in:
Bjørn Erik Pedersen
2026-05-23 12:12:51 +02:00
parent d8c70218b7
commit c4bbc2805c
13 changed files with 66 additions and 168 deletions
+3 -2
View File
@@ -26,6 +26,7 @@ import (
"time"
"github.com/bep/debounce"
"github.com/bep/helpers/maphelpers"
"github.com/bep/logg"
"github.com/gohugoio/go-radix"
"github.com/gohugoio/hugo/bufferpool"
@@ -692,7 +693,7 @@ func (h *HugoSites) postProcess(l logg.LevelLogger) error {
}
var toPostProcess []postpub.PostPublishedResource
for _, r := range h.ResourceSpec.PostProcessResources {
for _, r := range h.ResourceSpec.PostProcessResources.All() {
toPostProcess = append(toPostProcess, r)
}
@@ -758,7 +759,7 @@ func (h *HugoSites) postProcess(l logg.LevelLogger) error {
// Prepare for a new build.
for _, s := range h.Sites {
s.ResourceSpec.PostProcessResources = make(map[string]postpub.PostPublishedResource)
s.ResourceSpec.PostProcessResources = maphelpers.NewConcurrentMap[string, postpub.PostPublishedResource]()
}
return g.Wait()
+5 -10
View File
@@ -27,6 +27,7 @@ import (
"strings"
"sync"
"github.com/bep/helpers/maphelpers"
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/hstore"
"github.com/gohugoio/hugo/common/types"
@@ -286,24 +287,18 @@ type shortcodeParseInfo struct {
shortcodes []*shortcode
// All the shortcode names in this set.
nameSetMu sync.RWMutex
nameSet map[string]bool
nameSet *maphelpers.ConcurrentSet[string]
// Configuration
enableInlineShortcodes bool
}
func (s *shortcodeParseInfo) addName(name string) {
s.nameSetMu.Lock()
defer s.nameSetMu.Unlock()
s.nameSet[name] = true
s.nameSet.Add(name)
}
func (s *shortcodeParseInfo) hasName(name string) bool {
s.nameSetMu.RLock()
defer s.nameSetMu.RUnlock()
_, ok := s.nameSet[name]
return ok
return s.nameSet.Has(name)
}
func newShortcodeHandler(filename string, d *deps.Deps) *shortcodeParseInfo {
@@ -312,7 +307,7 @@ func newShortcodeHandler(filename string, d *deps.Deps) *shortcodeParseInfo {
firstTemplateStore: d.TemplateStore,
enableInlineShortcodes: d.ExecHelper.Sec().EnableInlineShortcodes,
shortcodes: make([]*shortcode, 0, 4),
nameSet: make(map[string]bool),
nameSet: maphelpers.NewConcurrentSet[string](),
}
return sh