[Git][ghc/ghc][wip/strings] More fix

Sebastian Graf (@sgraf812) gitlab at gitlab.haskell.org
Wed Aug 14 16:07:18 UTC 2024



Sebastian Graf pushed to branch wip/strings at Glasgow Haskell Compiler / GHC


Commits:
6d632276 by Sebastian Graf at 2024-08-14T18:07:13+02:00
More fix

- - - - -


1 changed file:

- compiler/GHC/Data/StringBuffer.hs


Changes:

=====================================
compiler/GHC/Data/StringBuffer.hs
=====================================
@@ -99,8 +99,8 @@ data StringBuffer
      len :: {-# UNPACK #-} !Int,
       -- length, i.e., *end* position of the buffer, exclusive
      cur :: {-# UNPACK #-} !Int
-      -- current pos. Invariant: cur < len. The true length of the represented
-      -- string is (len - cur - 1).
+      -- current pos. Invariant: cur <= len. The true length of the represented
+      -- string is (len - cur).
   }
   -- The buffer is assumed to be UTF-8 encoded, and furthermore
   -- we add three @\'\\0\'@ bytes to the end as sentinels so that the
@@ -330,10 +330,7 @@ byteDiff s1 s2 = cur s2 - cur s1
 -- | Restricts the length of the string buffer to the current position plus the
 -- given number of bytes.
 takeBytes :: Int -> StringBuffer -> StringBuffer
-takeBytes n s = assert (cur s + n < len s) s { len = cur s + n }
-
-byteLength :: StringBuffer -> Int
-byteLength s = len s - cur s - 1
+takeBytes n s = assert (cur s + n <= len s) s { len = cur s + n }
 
 -- | Check whether a 'StringBuffer' is empty (analogous to 'Data.List.null').
 atEnd :: StringBuffer -> Bool



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6d632276f24b2eb16a62ac45faf12716f40e6e0b

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6d632276f24b2eb16a62ac45faf12716f40e6e0b
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/20240814/136c676f/attachment-0001.html>


More information about the ghc-commits mailing list