]> source.dussan.org Git - gitea.git/commitdiff
markup: microoptimise for many short filenames in directory (#1534)
authormappu <mappu04@gmail.com>
Tue, 9 May 2017 14:20:22 +0000 (02:20 +1200)
committerLunny Xiao <xiaolunwen@gmail.com>
Tue, 9 May 2017 14:20:22 +0000 (22:20 +0800)
* 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()

modules/markup/markup.go
modules/markup/markup_test.go

index dc27997e8d035b54abac4ce9d269c1724cf65458..e1fae3a5a893b67dca0dace913d4236d459b8c02 100644 (file)
@@ -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."
 }
+
index 92caa8ff9661cb906857a1293a3b4b982c9c1c14..0dd2be3564c157e0d88ae264913378c123fba1e0 100644 (file)
@@ -25,6 +25,7 @@ func TestMisc_IsReadmeFile(t *testing.T) {
                "abcdefg",
                "abcdefghijklmnopqrstuvwxyz",
                "test.md.test",
+               "readmf",
        }
 
        for _, testCase := range trueTestCases {