Skip to content

Commit 9087c63

Browse files
committedSep 21, 2023
docs: note about Get() being slow due to file matching
Fixes #714
1 parent ccd8d68 commit 9087c63

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed
 

‎lexers/lexers.go

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ func Names(withAliases bool) []string {
3030
}
3131

3232
// Get a Lexer by name, alias or file extension.
33+
//
34+
// Note that this if there isn't an exact match on name or alias, this will
35+
// call Match(), so it is not efficient.
3336
func Get(name string) chroma.Lexer {
3437
return GlobalLexerRegistry.Get(name)
3538
}
@@ -40,6 +43,9 @@ func MatchMimeType(mimeType string) chroma.Lexer {
4043
}
4144

4245
// Match returns the first lexer matching filename.
46+
//
47+
// Note that this iterates over all file patterns in all lexers, so it's not
48+
// particularly efficient.
4349
func Match(filename string) chroma.Lexer {
4450
return GlobalLexerRegistry.Match(filename)
4551
}

‎lexers/lexers_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ func FileTestAnalysis(t *testing.T, lexer chroma.Lexer, actualFilepath, expected
179179
assert.NoError(t, err)
180180
assert.NoError(t, f.Close())
181181
} else {
182-
// fail via an assertion of string comparison for nicer diff output
183182
assert.Equal(t, string(expectedData), actualData.String())
184183
}
185184
}

‎registry.go

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ func (l *LexerRegistry) MatchMimeType(mimeType string) Lexer {
9797
}
9898

9999
// Match returns the first lexer matching filename.
100+
//
101+
// Note that this iterates over all file patterns in all lexers, so is not fast.
100102
func (l *LexerRegistry) Match(filename string) Lexer {
101103
filename = filepath.Base(filename)
102104
matched := PrioritisedLexers{}

0 commit comments

Comments
 (0)
Please sign in to comment.