[PATCH] highlight: do not use guess_lexer functions. they use too much CPU time for certain inputs
Ralf Schmitt
ralf at brainbot.com
Wed Apr 2 19:59:41 UTC 2008
# HG changeset patch
# User ralf at brainbot.com
# Date 1207165818 -7200
# Node ID 50015149baa0dbf1b7066f0356b65f492ed78450
# Parent 101526031d06d184559ae797687e50661b96156e
highlight: do not use guess_lexer functions. they use too much CPU time for certain inputs.
diff --git a/hgext/highlight.py b/hgext/highlight.py
--- a/hgext/highlight.py
+++ b/hgext/highlight.py
@@ -32,7 +32,7 @@
from pygments import highlight
from pygments.util import ClassNotFound
-from pygments.lexers import guess_lexer, guess_lexer_for_filename, TextLexer
+from pygments.lexers import get_lexer_for_filename, TextLexer
from pygments.formatters import HtmlFormatter
SYNTAX_CSS = ('\n<link rel="stylesheet" href="#staticurl#highlight.css" '
@@ -52,13 +52,9 @@
# To get multi-line strings right, we can't format line-by-line
try:
- lexer = guess_lexer_for_filename(fctx.path(), text,
- encoding=util._encoding)
+ lexer = get_lexer_for_filename(fctx.path())
except ClassNotFound:
- try:
- lexer = guess_lexer(text, encoding=util._encoding)
- except ClassNotFound:
- lexer = TextLexer(encoding=util._encoding)
+ lexer = TextLexer(encoding=util._encoding)
formatter = HtmlFormatter(style=style, encoding=util._encoding)
More information about the Mercurial
mailing list