Skip to content

Commit

Permalink
markup: microoptimise for many short filenames in directory (#1534)
Browse files Browse the repository at this point in the history
* 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()
  • Loading branch information
mappu authored and lunny committed May 9, 2017
1 parent d98a86d commit fd76f09
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions modules/markup/markup.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ func ReadmeFileType(name string) (string, bool) {
// IsReadmeFile reports whether name looks like a README file
// based on its name.
func IsReadmeFile(name string) bool {
name = strings.ToLower(name)
if len(name) < 6 {
return false
} else if len(name) == 6 {
}

name = strings.ToLower(name)
if len(name) == 6 {
return name == "readme"
}
return name[:7] == "readme."
}

1 change: 1 addition & 0 deletions modules/markup/markup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestMisc_IsReadmeFile(t *testing.T) {
"abcdefg",
"abcdefghijklmnopqrstuvwxyz",
"test.md.test",
"readmf",
}

for _, testCase := range trueTestCases {
Expand Down

0 comments on commit fd76f09

Please sign in to comment.