|
From: <mi...@us...> - 2023-11-19 21:19:26
|
Revision: 9481
http://sourceforge.net/p/docutils/code/9481
Author: milde
Date: 2023-11-19 21:19:20 +0000 (Sun, 19 Nov 2023)
Log Message:
-----------
Smartquotes optimizations part 3.
Skip regexp substitutions if there are no quotes to "educate".
Together, the optimizations bring down the time spent on the smartquotes transformation from
20% to 10% of the total rst2html5 conversion time.
(Tested with py-spy on `builthtml` of the Docutils docs directory.)
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/utils/smartquotes.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2023-11-19 09:44:17 UTC (rev 9480)
+++ trunk/docutils/HISTORY.txt 2023-11-19 21:19:20 UTC (rev 9481)
@@ -74,7 +74,8 @@
* docutils/utils/smartquotes.py
- Pre-compile regexps once, not with every call of `educateQuotes()`
- (patch #206 by Chris Sewell). Simplify regexps.
+ (patch #206 by Chris Sewell); simplify regexps; skip replacement
+ rules if there is nothing to replace.
* docutils/writers/latex2e/__init__.py
Modified: trunk/docutils/docutils/utils/smartquotes.py
===================================================================
--- trunk/docutils/docutils/utils/smartquotes.py 2023-11-19 09:44:17 UTC (rev 9480)
+++ trunk/docutils/docutils/utils/smartquotes.py 2023-11-19 21:19:20 UTC (rev 9481)
@@ -142,7 +142,7 @@
- Straight quotes ( " and ' ) into "curly" quote characters
- Backticks-style quotes (\`\`like this'') into "curly" quote characters
- Dashes (``--`` and ``---``) into en- and em-dash entities
-- Three consecutive dots (``...`` or ``. . .``) into an ellipsis entity
+- Three consecutive dots (``...`` or ``. . .``) into an ellipsis ``…``.
This means you can write, edit, and save your posts using plain old
ASCII straight quotes, plain dashes, and plain dots, but your published
@@ -548,6 +548,9 @@
""", re.VERBOSE)
+regexes = RegularExpressions()
+
+
default_smartypants_attr = '1'
@@ -679,10 +682,11 @@
Example input: "Isn't this fun?"
Example output: “Isn’t this fun?“
"""
-
smart = smartchars(language)
- regexes = RegularExpressions()
+ if not re.search('[-"\']', text):
+ return text
+
# Special case if the very first character is a quote
# followed by punctuation at a non-word-break. Use closing quotes.
# TODO: example (when does this match?)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|