mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	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()
This commit is contained in:
		| @@ -71,11 +71,14 @@ func ReadmeFileType(name string) (string, bool) { | |||||||
| // IsReadmeFile reports whether name looks like a README file | // IsReadmeFile reports whether name looks like a README file | ||||||
| // based on its name. | // based on its name. | ||||||
| func IsReadmeFile(name string) bool { | func IsReadmeFile(name string) bool { | ||||||
| 	name = strings.ToLower(name) |  | ||||||
| 	if len(name) < 6 { | 	if len(name) < 6 { | ||||||
| 		return false | 		return false | ||||||
| 	} else if len(name) == 6 { | 	} | ||||||
|  |  | ||||||
|  | 	name = strings.ToLower(name) | ||||||
|  | 	if len(name) == 6 { | ||||||
| 		return name == "readme" | 		return name == "readme" | ||||||
| 	} | 	} | ||||||
| 	return name[:7] == "readme." | 	return name[:7] == "readme." | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -25,6 +25,7 @@ func TestMisc_IsReadmeFile(t *testing.T) { | |||||||
| 		"abcdefg", | 		"abcdefg", | ||||||
| 		"abcdefghijklmnopqrstuvwxyz", | 		"abcdefghijklmnopqrstuvwxyz", | ||||||
| 		"test.md.test", | 		"test.md.test", | ||||||
|  | 		"readmf", | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for _, testCase := range trueTestCases { | 	for _, testCase := range trueTestCases { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user