Skip to content

Commit fd76f09

Browse files
mappulunny
authored andcommitted
markup: microoptimise for many short filenames in directory (#1534)
* markup: microoptimise for many short filenames in directory Move strings.ToLower() after the early-return length check. This is a safe operation in all cases and should slightly improve directory listing performance when a directory contains many thousands of files with short filenames. * markup: expand test cases for IsReadmeFile()
1 parent d98a86d commit fd76f09

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

modules/markup/markup.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,14 @@ func ReadmeFileType(name string) (string, bool) {
7171
// IsReadmeFile reports whether name looks like a README file
7272
// based on its name.
7373
func IsReadmeFile(name string) bool {
74-
name = strings.ToLower(name)
7574
if len(name) < 6 {
7675
return false
77-
} else if len(name) == 6 {
76+
}
77+
78+
name = strings.ToLower(name)
79+
if len(name) == 6 {
7880
return name == "readme"
7981
}
8082
return name[:7] == "readme."
8183
}
84+

modules/markup/markup_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func TestMisc_IsReadmeFile(t *testing.T) {
2525
"abcdefg",
2626
"abcdefghijklmnopqrstuvwxyz",
2727
"test.md.test",
28+
"readmf",
2829
}
2930

3031
for _, testCase := range trueTestCases {

0 commit comments

Comments
 (0)