[Git][ghc/ghc][wip/ftext-no-length] FastString: Remove cached length field
Sebastian Graf
gitlab at gitlab.haskell.org
Tue Sep 1 13:34:17 UTC 2020
Sebastian Graf pushed to branch wip/ftext-no-length at Glasgow Haskell Compiler / GHC
Commits:
8493e16f by Sebastian Graf at 2020-09-01T15:33:31+02:00
FastString: Remove cached length field
- - - - -
2 changed files:
- compiler/GHC/Data/FastString.hs
- compiler/GHC/Utils/Encoding.hs
Changes:
=====================================
compiler/GHC/Data/FastString.hs
=====================================
@@ -184,7 +184,6 @@ of this string which is used by the compiler internally.
-}
data FastString = FastString {
uniq :: {-# UNPACK #-} !Int, -- unique id
- n_chars :: {-# UNPACK #-} !Int, -- number of chars
fs_sbs :: {-# UNPACK #-} !ShortByteString,
fs_zenc :: FastZString
-- ^ Lazily computed z-encoding of this string.
@@ -499,8 +498,7 @@ mkNewFastStringShortByteString :: ShortByteString -> Int
-> IORef Int -> IO FastString
mkNewFastStringShortByteString sbs uid n_zencs = do
let zstr = mkZFastString n_zencs sbs
- chars <- countUTF8Chars sbs
- return (FastString uid chars sbs zstr)
+ return (FastString uid sbs zstr)
hashStr :: ShortByteString -> Int
-- produce a hash value between 0 & m (inclusive)
@@ -525,7 +523,7 @@ hashStr sbs@(SBS.SBS ba#) = loop 0# 0#
-- | Returns the length of the 'FastString' in characters
lengthFS :: FastString -> Int
-lengthFS fs = n_chars fs
+lengthFS FastString{fs_sbs=sbs} = countUTF8Chars sbs
-- | Returns @True@ if the 'FastString' is empty
nullFS :: FastString -> Bool
=====================================
compiler/GHC/Utils/Encoding.hs
=====================================
@@ -170,13 +170,13 @@ utf8DecodeShortByteString (SBS ba#)
let len# = sizeofByteArray# ba# in
utf8DecodeLazy# (return ()) (utf8DecodeCharByteArray# ba#) len#
-countUTF8Chars :: ShortByteString -> IO Int
+countUTF8Chars :: ShortByteString -> Int
countUTF8Chars (SBS ba) = go 0# 0#
where
len# = sizeofByteArray# ba
go i# n#
| isTrue# (i# >=# len#) =
- return (I# n#)
+ (I# n#)
| otherwise = do
case utf8DecodeCharByteArray# ba i# of
(# _, nBytes# #) -> go (i# +# nBytes#) (n# +# 1#)
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8493e16ffce91bab1d7b7bb46583d30da6e10599
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/8493e16ffce91bab1d7b7bb46583d30da6e10599
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200901/56f22a2f/attachment-0001.html>
More information about the ghc-commits
mailing list