internal/rosa: store artifact results in struct
All checks were successful
Test / Create distribution (push) Successful in 1m0s
Test / Sandbox (push) Successful in 2m39s
Test / Hakurei (push) Successful in 3m43s
Test / ShareFS (push) Successful in 3m40s
Test / Sandbox (race detector) (push) Successful in 5m6s
Test / Hakurei (race detector) (push) Successful in 6m8s
Test / Flake checks (push) Successful in 1m21s
All checks were successful
Test / Create distribution (push) Successful in 1m0s
Test / Sandbox (push) Successful in 2m39s
Test / Hakurei (push) Successful in 3m43s
Test / ShareFS (push) Successful in 3m40s
Test / Sandbox (race detector) (push) Successful in 5m6s
Test / Hakurei (race detector) (push) Successful in 6m8s
Test / Flake checks (push) Successful in 1m21s
This is cleaner and makes adding additional values easier. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -256,9 +256,10 @@ var (
|
|||||||
artifactsM [PresetEnd]Metadata
|
artifactsM [PresetEnd]Metadata
|
||||||
|
|
||||||
// artifacts stores the result of Metadata.f.
|
// artifacts stores the result of Metadata.f.
|
||||||
artifacts [_toolchainEnd][len(artifactsM)]pkg.Artifact
|
artifacts [_toolchainEnd][len(artifactsM)]struct {
|
||||||
// versions stores the version of [PArtifact].
|
a pkg.Artifact
|
||||||
versions [_toolchainEnd][len(artifactsM)]string
|
v string
|
||||||
|
}
|
||||||
// artifactsOnce is for lazy initialisation of artifacts.
|
// artifactsOnce is for lazy initialisation of artifacts.
|
||||||
artifactsOnce [_toolchainEnd][len(artifactsM)]sync.Once
|
artifactsOnce [_toolchainEnd][len(artifactsM)]sync.Once
|
||||||
)
|
)
|
||||||
@@ -266,20 +267,23 @@ var (
|
|||||||
// GetMetadata returns [Metadata] of a [PArtifact].
|
// GetMetadata returns [Metadata] of a [PArtifact].
|
||||||
func GetMetadata(p PArtifact) *Metadata { return &artifactsM[p] }
|
func GetMetadata(p PArtifact) *Metadata { return &artifactsM[p] }
|
||||||
|
|
||||||
|
// construct constructs a [pkg.Artifact] corresponding to a [PArtifact] once.
|
||||||
|
func (t Toolchain) construct(p PArtifact) {
|
||||||
|
artifactsOnce[t][p].Do(func() {
|
||||||
|
artifacts[t][p].a, artifacts[t][p].v = artifactsM[p].f(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Load returns the resulting [pkg.Artifact] of [PArtifact].
|
// Load returns the resulting [pkg.Artifact] of [PArtifact].
|
||||||
func (t Toolchain) Load(p PArtifact) pkg.Artifact {
|
func (t Toolchain) Load(p PArtifact) pkg.Artifact {
|
||||||
artifactsOnce[t][p].Do(func() {
|
t.construct(p)
|
||||||
artifacts[t][p], versions[t][p] = artifactsM[p].f(t)
|
return artifacts[t][p].a
|
||||||
})
|
|
||||||
return artifacts[t][p]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version returns the version string of [PArtifact].
|
// Version returns the version string of [PArtifact].
|
||||||
func (t Toolchain) Version(p PArtifact) string {
|
func (t Toolchain) Version(p PArtifact) string {
|
||||||
artifactsOnce[t][p].Do(func() {
|
t.construct(p)
|
||||||
artifacts[t][p], versions[t][p] = artifactsM[p].f(t)
|
return artifacts[t][p].v
|
||||||
})
|
|
||||||
return versions[t][p]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResolveName returns a [PArtifact] by name.
|
// ResolveName returns a [PArtifact] by name.
|
||||||
|
|||||||
Reference in New Issue
Block a user