[GHC] #5218: Add unpackCStringLen# to create Strings from string literals

GHC cvs-ghc at haskell.org
Wed May 25 10:48:29 CEST 2011


#5218: Add unpackCStringLen# to create Strings from string literals
---------------------------------+------------------------------------------
    Reporter:  tibbe             |       Owner:              
        Type:  feature request   |      Status:  new         
    Priority:  normal            |   Component:  Compiler    
     Version:  7.0.3             |    Keywords:              
    Testcase:                    |   Blockedby:              
          Os:  Unknown/Multiple  |    Blocking:              
Architecture:  Unknown/Multiple  |     Failure:  None/Unknown
---------------------------------+------------------------------------------
 GHC insert calls to `unpackCString#` to convert string literals to
 `String`s. Libraries like bytestring use rewrite rules to match on this
 call to optimize code like `pack (unpackCString# s)`.

 If GHC would instead use a version of unpackCString#, say
 unpackCStringLen#, that includes the (statically known) length, creating
 `ByteString`s from literals could be a constant time operation instead of
 a linear time operation.

 Another use case, which motivated this ticket, is appending string
 literals to builders (e.g. using `Data.Binary.Builder.fromByteString`).
 For small strings the most efficient way to append a string to the builder
 is to copy the statically allocated string directly into the builder's
 output buffer. If the string length was known statically, we could do this
 efficiently using `memcpy` or even using a small unrolled loop.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5218>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler



More information about the Glasgow-haskell-bugs mailing list