JavaScript: Re-add optimisation for literal strings
In GHCJS, the genApp
function contained an optimisation for unpacking string literals:
-- special cases for JSString literals
-- we could handle unpackNBytes# here, but that's probably not common
-- enough to warrant a special case
| [StgVarArg v] <- args
, [top] <- concatMap snd (ctxTarget ctx)
, matchVarName "ghcjs-prim" "GHCJS.Prim" "unsafeUnpackJSStringUtf8##" i =
(,ExprInline Nothing) . (|=) top . app "h$decodeUtf8z" <$> varsForId v
This wasn't ported with the JavaScript backend, but should be added now in GHC.StgToJS.Apply.genApp
.
This optimization too:
genApp ctx i [StgLitArg (LitString bs), x]
| [top] <- concatMap snd (ctx ^. ctxTarget), getUnique i == unpackCStringAppendIdKey, Just d <- decodeModifiedUTF8 bs = do
-- fixme breaks assumption in codegen if bs doesn't decode
prof <- csProf <$> use gsSettings
let profArg = if prof then [jCafCCS] else []
a <- genArg x
return (top |= app "h$appendToHsStringA" ([toJExpr d, toJExpr a] ++ profArg)
,ExprInline Nothing)
Edited by Sylvain Henry