summaryrefslogtreecommitdiffstats
path: root/modules/markup
diff options
context:
space:
mode:
authormappu <mappu04@gmail.com>2017-05-10 02:20:22 +1200
committerLunny Xiao <xiaolunwen@gmail.com>2017-05-09 22:20:22 +0800
commitfd76f090a29b229b9e8e089e225f7ca012809090 (patch)
tree88e601c8a35d6df5aa3b945f76fa4cb339b236c2 /modules/markup
parentd98a86d2a2f9c12955316aff5723e03f14c0fe5d (diff)
downloadgitea-fd76f090a29b229b9e8e089e225f7ca012809090.tar.gz
gitea-fd76f090a29b229b9e8e089e225f7ca012809090.zip
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()
Diffstat (limited to 'modules/markup')
-rw-r--r--modules/markup/markup.go7
-rw-r--r--modules/markup/markup_test.go1
2 files changed, 6 insertions, 2 deletions
diff --git a/modules/markup/markup.go b/modules/markup/markup.go
index dc27997e8d..e1fae3a5a8 100644
--- a/modules/markup/markup.go
+++ b/modules/markup/markup.go
@@ -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."
}
+
diff --git a/modules/markup/markup_test.go b/modules/markup/markup_test.go
index 92caa8ff96..0dd2be3564 100644
--- a/modules/markup/markup_test.go
+++ b/modules/markup/markup_test.go
@@ -25,6 +25,7 @@ func TestMisc_IsReadmeFile(t *testing.T) {
"abcdefg",
"abcdefghijklmnopqrstuvwxyz",
"test.md.test",
+ "readmf",
}
for _, testCase := range trueTestCases {