Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

markup: microoptimise for many short filenames in directory #1534

Merged
merged 2 commits into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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."
Copy link
Member

@sapk sapk Apr 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this be simplify by just return name == "readme" || name[:7] == "readme." and remove if len(name) == 6 bracket ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just return/check name[:6] == "readme" this would also validate file like README_LANGUAGE.md ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mappu can you update the source code base on @sapk suggestions?

return name == "readme" || 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