pkg/reference: SplitObject: zero allocations
Before / After:
    BenchmarkSplitObject-10        2785656    428.1 ns/op     416 B/op    13 allocs/op
    BenchmarkSplitObjectNew-10    13510520     88.2 ns/op       0 B/op     0 allocs/op
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
			
			
This commit is contained in:
		@@ -157,9 +157,9 @@ func (r Spec) String() string {
 | 
			
		||||
// Either may be empty and it is the callers job to validate them
 | 
			
		||||
// appropriately.
 | 
			
		||||
func SplitObject(obj string) (tag string, dgst digest.Digest) {
 | 
			
		||||
	parts := strings.SplitAfterN(obj, "@", 2)
 | 
			
		||||
	if len(parts) < 2 {
 | 
			
		||||
		return parts[0], ""
 | 
			
		||||
	if i := strings.Index(obj, "@"); i >= 0 {
 | 
			
		||||
		// Offset by one so preserve the "@" in the tag returned.
 | 
			
		||||
		return obj[:i+1], digest.Digest(obj[i+1:])
 | 
			
		||||
	}
 | 
			
		||||
	return parts[0], digest.Digest(parts[1])
 | 
			
		||||
	return obj, ""
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user