Commit 3ed107ba authored by Steffen Michels's avatar Steffen Michels

Merge branch 'optimise-string-concat' into 'master'

Optimise concat for String

See merge request !255
parents bf8c9499 5d3bc6c9
Pipeline #23905 passed with stage
in 3 minutes and 51 seconds
implementation module Text implementation module Text
import qualified StdArray
import StdOverloaded, StdString, StdArray, StdChar, StdInt, StdBool, StdClass, StdList import StdOverloaded, StdString, StdArray, StdChar, StdInt, StdBool, StdClass, StdList
import Data.List import Data.List
...@@ -9,16 +10,15 @@ instance Text String ...@@ -9,16 +10,15 @@ instance Text String
textSize s = size s textSize s = size s
concat :: ![String] -> String concat :: ![String] -> String
concat xs = concat` xs (createArray (foldl (\s a -> s+size a) 0 xs) '\0') 0 concat xs = concat` xs ('StdArray'._createArray (foldl (\s a -> s+size a) 0 xs)) 0
where where
concat` :: ![String] !*String !Int -> *String concat` :: ![String] !*String !Int -> *String
concat` [] dst _ = dst concat` [] dst _ = dst
concat` [x:xs] dst offset = concat` xs (copyChars offset 0 (size x) x dst) (offset + size x) concat` [x:xs] dst offset = concat` xs (copyChars offset (size x-1) x dst) (offset + size x)
copyChars :: !Int !Int !Int !String !*String -> *String copyChars :: !Int !Int !String !*String -> *String
copyChars offset i num src dst copyChars _ -1 _ dst = dst
| i == num = dst copyChars offset i src dst = copyChars offset (i-1) src {dst & [offset+i]=src.[i]}
| otherwise = copyChars offset (inc i) num src {dst & [offset + i] = src.[i]}
split :: !String !String -> [String] split :: !String !String -> [String]
split sep s = splitAfter 0 (size s-1) sep s split sep s = splitAfter 0 (size s-1) sep s
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment