Skip to content
This repository
Browse code

Get rid of the old decode function

--HG--
extra : convert_revision : 7e57067
  • Loading branch information...
commit 4667a184f421ca6f077eb91800cd8beb8285db94 1 parent be3f9d8
Bryan O'Sullivan authored October 14, 2010
28  Data/Text/Encoding.hs
@@ -22,14 +22,12 @@ module Data.Text.Encoding
22 22
     -- * Decoding ByteStrings to Text
23 23
       decodeASCII
24 24
     , decodeUtf8
25  
-    , decodeUtf8'
26 25
     , decodeUtf16LE
27 26
     , decodeUtf16BE
28 27
     , decodeUtf32LE
29 28
     , decodeUtf32BE
30 29
     -- ** Controllable error handling
31 30
     , decodeUtf8With
32  
-    , decodeUtf8With'
33 31
     , decodeUtf16LEWith
34 32
     , decodeUtf16BEWith
35 33
     , decodeUtf32LEWith
@@ -67,18 +65,8 @@ decodeASCII :: ByteString -> Text
67 65
 decodeASCII bs = F.unstream (E.streamASCII bs)
68 66
 {-# INLINE decodeASCII #-}
69 67
 
70  
--- | Decode a 'ByteString' containing UTF-8 encoded text.
71 68
 decodeUtf8With :: OnDecodeError -> ByteString -> Text
72  
-decodeUtf8With onErr bs = F.unstream (E.streamUtf8 onErr bs)
73  
-{-# INLINE decodeUtf8With #-}
74  
-
75  
--- | Decode a 'ByteString' containing UTF-8 encoded text.
76  
-decodeUtf8 :: ByteString -> Text
77  
-decodeUtf8 = decodeUtf8With strictDecode
78  
-{-# INLINE decodeUtf8 #-}
79  
-
80  
-decodeUtf8With' :: OnDecodeError -> ByteString -> Text
81  
-decodeUtf8With' onErr bs = textP (fst a) 0 (snd a)
  69
+decodeUtf8With onErr bs = textP (fst a) 0 (snd a)
82 70
  where
83 71
   a   = A.run2 (A.new len >>= outer 0 0)
84 72
   len = B.length bs
@@ -109,16 +97,16 @@ decodeUtf8With' onErr bs = textP (fst a) 0 (snd a)
109 97
                          Just c -> do
110 98
                            w <- unsafeWrite arr n c
111 99
                            go (n+w) (m+1)
112  
-  desc = "Data.Text.Encoding.encodeUtf8: Invalid UTF-8 stream"
113  
-{-# INLINE[0] decodeUtf8With' #-}
  100
+  desc = "Data.Text.Encoding.decodeUtf8: Invalid UTF-8 stream"
  101
+{-# INLINE[0] decodeUtf8With #-}
114 102
 
115 103
 -- | Decode a 'ByteString' containing UTF-8 encoded text.
116  
-decodeUtf8' :: ByteString -> Text
117  
-decodeUtf8' = decodeUtf8With' strictDecode
118  
-{-# INLINE[0] decodeUtf8' #-}
  104
+decodeUtf8 :: ByteString -> Text
  105
+decodeUtf8 = decodeUtf8With strictDecode
  106
+{-# INLINE[0] decodeUtf8 #-}
119 107
 
120  
-{-# RULES "STREAM stream/decodeUtf8' fusion" [1]
121  
-    forall bs. F.stream (decodeUtf8' bs) = E.streamUtf8 strictDecode bs #-}
  108
+{-# RULES "STREAM stream/decodeUtf8 fusion" [1]
  109
+    forall bs. F.stream (decodeUtf8 bs) = E.streamUtf8 strictDecode bs #-}
122 110
 
123 111
 -- | Encode text using UTF-8 encoding.
124 112
 encodeUtf8 :: Text -> ByteString
19  tests/benchmarks/DecodeUtf8.hs
@@ -15,23 +15,24 @@ strict h = do
15 15
   bs <- B.hGetContents h
16 16
   rnf (T.decodeUtf8 bs) `seq` return ()
17 17
 
18  
-strict_ h = do
19  
-  bs <- B.hGetContents h
20  
-  rnf (T.decodeUtf8' bs) `seq` return ()
21  
-
22 18
 strict_len h = do
23 19
   bs <- B.hGetContents h
24  
-  print . T.length . T.init . T.decodeUtf8 $ bs
  20
+  print . T.length . T.decodeUtf8 $ bs
25 21
 
26  
-strict__len h = do
  22
+strict_init_len h = do
27 23
   bs <- B.hGetContents h
28  
-  print . T.length . T.init . T.decodeUtf8' $ bs
  24
+  print . T.length . T.init . T.decodeUtf8 $ bs
29 25
 
30 26
 strict_io h = do
31 27
   hSetEncoding h utf8
32 28
   t <- T.hGetContents h
33 29
   rnf t `seq` return ()
34 30
 
  31
+strict_len_io h = do
  32
+  hSetEncoding h utf8
  33
+  t <- T.hGetContents h
  34
+  print (T.length t)
  35
+
35 36
 lazy h = do
36 37
   bs <- BL.hGetContents h
37 38
   rnf (TL.decodeUtf8 bs) `seq` return ()
@@ -51,10 +52,10 @@ main = do
51 52
   h <- openFile name ReadMode
52 53
   case kind of
53 54
     "strict" -> strict h
54  
-    "strict_" -> strict_ h
55  
-    "strict__len" -> strict__len h
56 55
     "strict_len" -> strict_len h
  56
+    "strict_init_len" -> strict_init_len h
57 57
     "strict_io" -> strict_io h
  58
+    "strict_len_io" -> strict_len_io h
58 59
     "lazy" -> lazy h
59 60
     "lazy_io" -> lazy_io h
60 61
     "string" -> string h

0 notes on commit 4667a18

Please sign in to comment.
Something went wrong with that request. Please try again.