Skip to content

Commit 2568684

Browse files
committed
use foldr, avoid n^2 behavior in combineParts
1 parent 861cf54 commit 2568684

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/Database/PostgreSQL/Simple/SqlQQ/Interpolated.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module Database.PostgreSQL.Simple.SqlQQ.Interpolated (isql, quoteInterpolatedSql
55

66
import Language.Haskell.TH (Exp, Q, appE, listE, sigE, tupE, varE)
77
import Language.Haskell.TH.Quote (QuasiQuoter (..))
8-
import Data.List (foldl')
98
import Database.PostgreSQL.Simple.ToField (Action, toField)
109
import Database.PostgreSQL.Simple.SqlQQ (sql)
1110
import Text.Parsec (ParseError)
@@ -48,12 +47,12 @@ isql = QuasiQuoter
4847
}
4948

5049
combineParts :: [StringPart] -> (String, [Q Exp])
51-
combineParts = foldl' step ("", [])
50+
combineParts = foldr step ("", [])
5251
where
53-
step (s, exprs) subExpr = case subExpr of
54-
Lit str -> (s <> str, exprs)
55-
Esc c -> (s <> [c], exprs)
56-
Anti e -> (s <> "?", exprs <> [e]) -- TODO: Make this not slow
52+
step subExpr (s, exprs) = case subExpr of
53+
Lit str -> (str <> s, exprs)
54+
Esc c -> (c : s, exprs)
55+
Anti e -> ('?' : s, e : exprs)
5756

5857
applySql :: [StringPart] -> Q Exp
5958
applySql parts =

0 commit comments

Comments
 (0)