Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1384)

Unified Diff: pkg/dartdoc/lib/src/markdown/inline_parser.dart

Issue 11086016: Speed up markdown parsing with fast path for plain words. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/dartdoc/lib/src/markdown/inline_parser.dart
diff --git a/pkg/dartdoc/lib/src/markdown/inline_parser.dart b/pkg/dartdoc/lib/src/markdown/inline_parser.dart
index d396f2d8b8430cd00768c3809a5782d9b613a4f4..587edf7745b7308e15ac5cbfc382203ae43e8cb1 100644
--- a/pkg/dartdoc/lib/src/markdown/inline_parser.dart
+++ b/pkg/dartdoc/lib/src/markdown/inline_parser.dart
@@ -9,6 +9,18 @@ class InlineParser {
// Lazy initialize.
if (_syntaxes == null) {
_syntaxes = <InlineSyntax>[
+ // This first regexp matches plain text to accelerate parsing. It must
+ // be written so that it does not match any prefix of any following
+ // syntax. Most markdown is plain text, so it is faster to match one
+ // regexp per 'word' rather than fail to match all the following regexps
+ // at each non-syntax character position. It is much more important
+ // that the regexp is fast than complete (for example, adding grouping
+ // is likely to slow the regexp down enough to negate its benefit).
+ // Since it is purely for optimization, it can be removed for debugging.
+ new TextSyntax(r'\s*[A-Za-z0-9]+'),
+
+ // The real syntaxes.
+
new AutolinkSyntax(),
new LinkSyntax(),
// "*" surrounded by spaces is left alone.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698