diff options
author | Bjørn Erik Pedersen <[email protected]> | 2021-07-13 11:41:02 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2021-07-15 17:14:26 +0200 |
commit | 022c4795510306e08a4aba31504ca382d41c7fac (patch) | |
tree | d4c29f62038d0f336d90f32f46bc5b4f5c3ddc28 /hugofs/rootmapping_fs.go | |
parent | f27e542442d19436f1428cc22bb03aca398d37a7 (diff) | |
download | hugo-022c4795510306e08a4aba31504ca382d41c7fac.tar.gz hugo-022c4795510306e08a4aba31504ca382d41c7fac.zip |
hugofs: Make FileMeta a struct
This commit started out investigating a `concurrent map read write` issue, ending by replacing the map with a struct.
This is easier to reason about, and it's more effective:
```
name old time/op new time/op delta
SiteNew/Regular_Deep_content_tree-16 71.5ms ± 3% 69.4ms ± 5% ~ (p=0.200 n=4+4)
name old alloc/op new alloc/op delta
SiteNew/Regular_Deep_content_tree-16 29.7MB ± 0% 27.9MB ± 0% -5.82% (p=0.029 n=4+4)
name old allocs/op new allocs/op delta
SiteNew/Regular_Deep_content_tree-16 313k ± 0% 303k ± 0% -3.35% (p=0.029 n=4+4)
```
See #8749
Diffstat (limited to 'hugofs/rootmapping_fs.go')
-rw-r--r-- | hugofs/rootmapping_fs.go | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/hugofs/rootmapping_fs.go b/hugofs/rootmapping_fs.go index 4ffdb9c66..6441693ad 100644 --- a/hugofs/rootmapping_fs.go +++ b/hugofs/rootmapping_fs.go @@ -55,19 +55,19 @@ func NewRootMappingFs(fs afero.Fs, rms ...RootMapping) (*RootMappingFs, error) { // Extract "blog" from "content/blog" rm.path = strings.TrimPrefix(strings.TrimPrefix(rm.From, fromBase), filepathSeparator) if rm.Meta == nil { - rm.Meta = make(FileMeta) + rm.Meta = NewFileMeta() } - rm.Meta[metaKeySourceRoot] = rm.To - rm.Meta[metaKeyBaseDir] = rm.ToBasedir - rm.Meta[metaKeyMountRoot] = rm.path - rm.Meta[metaKeyModule] = rm.Module + rm.Meta.SourceRoot = rm.To + rm.Meta.BaseDir = rm.ToBasedir + rm.Meta.MountRoot = rm.path + rm.Meta.Module = rm.Module - meta := copyFileMeta(rm.Meta) + meta := rm.Meta.Copy() if !fi.IsDir() { _, name := filepath.Split(rm.From) - meta[metaKeyName] = name + meta.Name = name } rm.fi = NewFileMetaInfo(fi, meta) @@ -114,11 +114,11 @@ func newRootMappingFsFromFromTo( // RootMapping describes a virtual file or directory mount. type RootMapping struct { - From string // The virtual mount. - To string // The source directory or file. - ToBasedir string // The base of To. May be empty if an absolute path was provided. - Module string // The module path/ID. - Meta FileMeta // File metadata (lang etc.) + From string // The virtual mount. + To string // The source directory or file. + ToBasedir string // The base of To. May be empty if an absolute path was provided. + Module string // The module path/ID. + Meta *FileMeta // File metadata (lang etc.) fi FileMetaInfo path string // The virtual mount point, e.g. "blog". @@ -177,7 +177,7 @@ func (fs *RootMappingFs) Dirs(base string) ([]FileMetaInfo, error) { } if !fi.IsDir() { - mergeFileMeta(r.Meta, fi.(FileMetaInfo).Meta()) + fi.(FileMetaInfo).Meta().Merge(r.Meta) } fss[i] = fi.(FileMetaInfo) @@ -304,7 +304,7 @@ func (fs *RootMappingFs) newUnionFile(fis ...FileMetaInfo) (afero.File, error) { return f, nil } - rf := &rootMappingFile{File: f, fs: fs, name: meta.Name(), meta: meta} + rf := &rootMappingFile{File: f, fs: fs, name: meta.Name, meta: meta} if len(fis) == 1 { return rf, err } @@ -367,7 +367,7 @@ func (fs *RootMappingFs) collectDirEntries(prefix string) ([]os.FileInfo, error) for _, fi := range direntries { meta := fi.(FileMetaInfo).Meta() - mergeFileMeta(rm.Meta, meta) + meta.Merge(rm.Meta) if fi.IsDir() { name := fi.Name() if seen[name] { @@ -556,7 +556,7 @@ func (fs *RootMappingFs) virtualDirOpener(name string) func() (afero.File, error return func() (afero.File, error) { return &rootMappingFile{name: name, fs: fs}, nil } } -func (fs *RootMappingFs) realDirOpener(name string, meta FileMeta) func() (afero.File, error) { +func (fs *RootMappingFs) realDirOpener(name string, meta *FileMeta) func() (afero.File, error) { return func() (afero.File, error) { f, err := fs.Fs.Open(name) if err != nil { @@ -570,7 +570,7 @@ type rootMappingFile struct { afero.File fs *RootMappingFs name string - meta FileMeta + meta *FileMeta } func (f *rootMappingFile) Close() error { |