From cbbbf312ea2fa64e03cbcfa0cf3c3876736d7c8a Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 9 Sep 2026 17:38:41 +0000 Subject: [PATCH] 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 --- src/Text/Pandoc/Class/PandocMonad.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Text/Pandoc/Class/PandocMonad.hs b/src/Text/Pandoc/Class/PandocMonad.hs index 5614b5aea..810852166 100644 --- a/src/Text/Pandoc/Class/PandocMonad.hs +++ b/src/Text/Pandoc/Class/PandocMonad.hs @@ -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@