mirror of
https://github.com/go-gitea/gitea
synced 2025-11-19 12:48:12 +00:00
Backport #15059 Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
12
vendor/github.com/yuin/goldmark/parser/parser.go
generated
vendored
12
vendor/github.com/yuin/goldmark/parser/parser.go
generated
vendored
@@ -138,6 +138,9 @@ type Context interface {
|
||||
// Get returns a value associated with the given key.
|
||||
Get(ContextKey) interface{}
|
||||
|
||||
// ComputeIfAbsent computes a value if a value associated with the given key is absent and returns the value.
|
||||
ComputeIfAbsent(ContextKey, func() interface{}) interface{}
|
||||
|
||||
// Set sets the given value to the context.
|
||||
Set(ContextKey, interface{})
|
||||
|
||||
@@ -252,6 +255,15 @@ func (p *parseContext) Get(key ContextKey) interface{} {
|
||||
return p.store[key]
|
||||
}
|
||||
|
||||
func (p *parseContext) ComputeIfAbsent(key ContextKey, f func() interface{}) interface{} {
|
||||
v := p.store[key]
|
||||
if v == nil {
|
||||
v = f()
|
||||
p.store[key] = v
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (p *parseContext) Set(key ContextKey, value interface{}) {
|
||||
p.store[key] = value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user