Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
588901f4
Unverified
Commit
588901f4
authored
Apr 30, 2024
by
Blake Mizerany
Committed by
GitHub
Apr 30, 2024
Browse files
types/model: reduce Name.Filepath allocs from 5 to 2 (#4039)
parent
0a7fdbe5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
6 deletions
+21
-6
types/model/name.go
types/model/name.go
+6
-6
types/model/name_test.go
types/model/name_test.go
+15
-0
No files found.
types/model/name.go
View file @
588901f4
...
@@ -231,12 +231,12 @@ func (n Name) Filepath() string {
...
@@ -231,12 +231,12 @@ func (n Name) Filepath() string {
if
!
n
.
IsFullyQualified
()
{
if
!
n
.
IsFullyQualified
()
{
panic
(
"illegal attempt to get filepath of invalid name"
)
panic
(
"illegal attempt to get filepath of invalid name"
)
}
}
return
filepath
.
Join
(
return
strings
.
ToLower
(
filepath
.
Join
(
strings
.
ToLower
(
n
.
Host
)
,
n
.
Host
,
strings
.
ToLower
(
n
.
Namespace
)
,
n
.
Namespace
,
strings
.
ToLower
(
n
.
Model
)
,
n
.
Model
,
strings
.
ToLower
(
n
.
Tag
)
,
n
.
Tag
,
)
)
)
}
}
// LogValue returns a slog.Value that represents the name as a string.
// LogValue returns a slog.Value that represents the name as a string.
...
...
types/model/name_test.go
View file @
588901f4
...
@@ -2,6 +2,7 @@ package model
...
@@ -2,6 +2,7 @@ package model
import
(
import
(
"reflect"
"reflect"
"runtime"
"testing"
"testing"
)
)
...
@@ -217,6 +218,20 @@ func TestNameIsValidPart(t *testing.T) {
...
@@ -217,6 +218,20 @@ func TestNameIsValidPart(t *testing.T) {
}
}
func
TestFilepathAllocs
(
t
*
testing
.
T
)
{
n
:=
ParseNameBare
(
"HOST/NAMESPACE/MODEL:TAG"
)
allocs
:=
testing
.
AllocsPerRun
(
1000
,
func
()
{
n
.
Filepath
()
})
allowedAllocs
:=
2.0
if
runtime
.
GOOS
==
"windows"
{
allowedAllocs
=
4
}
if
allocs
>
allowedAllocs
{
t
.
Errorf
(
"allocs = %v; allowed %v"
,
allocs
,
allowedAllocs
)
}
}
func
FuzzName
(
f
*
testing
.
F
)
{
func
FuzzName
(
f
*
testing
.
F
)
{
for
s
:=
range
testCases
{
for
s
:=
range
testCases
{
f
.
Add
(
s
)
f
.
Add
(
s
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment