summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/GHC/Data/FastString.hs6
-rw-r--r--compiler/GHC/Utils/Encoding.hs4
2 files changed, 4 insertions, 6 deletions
diff --git a/compiler/GHC/Data/FastString.hs b/compiler/GHC/Data/FastString.hs
index fbd69d426f..ff56557794 100644
--- a/compiler/GHC/Data/FastString.hs
+++ b/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
diff --git a/compiler/GHC/Utils/Encoding.hs b/compiler/GHC/Utils/Encoding.hs
index 24637a3bff..ac4d4e01e5 100644
--- a/compiler/GHC/Utils/Encoding.hs
+++ b/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#)