@@ -119,8 +119,6 @@ decode UtfTail1 point word = case word of
119
119
w | 0x80 <= w && w <= 0xbf -> (UtfGround , setByte1 point word)
120
120
_ -> throwDecodeError
121
121
122
- {-# INLINE decode #-}
123
-
124
122
decodeHex :: Word8 -> Word16
125
123
decodeHex 48 = 0 -- '0'
126
124
decodeHex 49 = 1 -- '1'
@@ -145,12 +143,12 @@ decodeHex 101 = 14 -- 'e'
145
143
decodeHex 70 = 15 -- 'F'
146
144
decodeHex 102 = 15 -- 'f'
147
145
decodeHex _ = throwDecodeError
148
- {-# INLINE decodeHex #-}
149
146
150
147
unescapeText' :: ByteString -> Text
151
148
unescapeText' bs = runText $ \ done -> do
152
149
dest <- A. new len
153
- (pos, finalState) <- B. foldl' (f' dest) (return (0 , StateNone )) bs
150
+
151
+ (pos, finalState) <- loop dest (0 , StateNone ) 0
154
152
155
153
-- Check final state. Currently pos gets only increased over time, so this check should catch overflows.
156
154
when ( finalState /= StateNone || pos > len)
@@ -172,11 +170,11 @@ unescapeText' bs = runText $ \done -> do
172
170
(st', p) ->
173
171
return (pos, StateUtf st' p)
174
172
175
- {-# INLINE runUtf #-}
176
-
177
- f' dest m c = m >>= \ s -> f dest s c
178
-
179
- {-# INLINE f' #-}
173
+ loop _ ps i | i >= len = return ps
174
+ loop dest ps i = do
175
+ let c = B. index bs i -- JP: We can use unsafe index once we prove bounds with Liquid Haskell.
176
+ ps' <- f dest ps c
177
+ loop dest ps' $ i + 1
180
178
181
179
-- No pending state.
182
180
f dest (pos, StateNone ) c = runUtf dest pos UtfGround 0 c
@@ -253,8 +251,6 @@ unescapeText' bs = runText $ \done -> do
253
251
else
254
252
writeAndReturn dest pos u StateNone
255
253
256
- {-# INLINE f #-}
257
-
258
254
write :: A. MArray s -> Int -> Word16 -> ST s ()
259
255
write dest pos char =
260
256
A. unsafeWrite dest pos char
@@ -270,8 +266,6 @@ throwDecodeError :: a
270
266
throwDecodeError =
271
267
let desc = " Data.Text.Internal.Encoding.decodeUtf8: Invalid UTF-8 stream" in
272
268
throw (DecodeError desc Nothing )
273
- {-# INLINE throwDecodeError #-}
274
269
275
270
unescapeText :: ByteString -> Either UnicodeException Text
276
271
unescapeText = unsafeDupablePerformIO . try . evaluate . unescapeText'
277
- {-# INLINE unescapeText #-}
0 commit comments