Text.Pandoc.Class.PandocMonad: avoid copying input in toTextM.

Skip the CR-filtering copy when the input contains no CRs,
as already done in Text.Pandoc.UTF8.toText.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
John MacFarlane
2026-09-09 17:38:41 +00:00
co-authored by Claude
parent 762d6384b2
commit cbbbf312ea
+5 -1
View File
@@ -479,7 +479,11 @@ toTextM fp bs =
if "\xEF\xBB\xBF" `B.isPrefixOf` bs'
then B.drop 3 bs'
else bs'
filterCRs = B.filter (/=13)
-- Only allocate a filtered copy if a CR is actually present;
-- B.elem compiles to a fast memchr.
filterCRs bs' = if 13 `B.elem` bs'
then B.filter (/=13) bs'
else bs'
-- | Returns @fp@ if the file exists in the current directory; otherwise
-- searches for the data file relative to @/subdir/@. Returns @Nothing@