Don't add duplicates into string consts
authorunc0rr
Tue, 24 Apr 2012 16:11:07 +0400
changeset 6921 e6033fe39b7f
parent 6920 b1d0d26d41fa
child 6922 93bdd3d251fe
Don't add duplicates into string consts
tools/pas2c.hs
--- a/tools/pas2c.hs	Tue Apr 24 06:53:39 2012 +0200
+++ b/tools/pas2c.hs	Tue Apr 24 16:11:07 2012 +0400
@@ -46,10 +46,16 @@
     
 addStringConst :: String -> State RenderState Doc
 addStringConst str = do
-    i <- getUniq
-    let sn = "__str" ++ show i
-    modify (\s -> s{lastType = BTString, stringConsts = (sn, str) : stringConsts s})
-    return $ text sn
+    strs <- gets stringConsts
+    let a = find ((==) str . snd) strs
+    if isJust a then
+        return . text . fst . fromJust $ a
+    else
+        do
+        i <- getUniq
+        let sn = "__str" ++ show i
+        modify (\s -> s{lastType = BTString, stringConsts = (sn, str) : strs})
+        return $ text sn
     
 escapeStr :: String -> String
 escapeStr = foldr escapeChar []