From 44637f03ccef3f005da41da5d1880df80cceebb2 Mon Sep 17 00:00:00 2001 From: Unknwon <u@gogs.io> Date: Sun, 27 Dec 2015 17:02:36 -0500 Subject: #2282 fast detection of utf-8 --- modules/base/tool.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'modules/base/tool.go') diff --git a/modules/base/tool.go b/modules/base/tool.go index 75f475fa..5927dad0 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -18,6 +18,7 @@ import ( "regexp" "strings" "time" + "unicode/utf8" "github.com/Unknwon/com" "github.com/Unknwon/i18n" @@ -53,6 +54,11 @@ func ShortSha(sha1 string) string { } func DetectEncoding(content []byte) string { + if utf8.Valid(content[:1024]) { + log.Debug("Detected encoding: utf-8 (fast)") + return "utf-8" + } + _, name, certain := charset.DetermineEncoding(content, "") if name != "utf-8" && len(setting.Repository.AnsiCharset) > 0 { log.Debug("Using default AnsiCharset: %s", setting.Repository.AnsiCharset) -- cgit v1.2.3