diff options
Diffstat (limited to 'compiler/GHC/Data/StringBuffer.hs')
-rw-r--r-- | compiler/GHC/Data/StringBuffer.hs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/compiler/GHC/Data/StringBuffer.hs b/compiler/GHC/Data/StringBuffer.hs index c2dd8e2208..749f64b09e 100644 --- a/compiler/GHC/Data/StringBuffer.hs +++ b/compiler/GHC/Data/StringBuffer.hs @@ -32,6 +32,7 @@ module GHC.Data.StringBuffer currentChar, prevChar, atEnd, + fingerprintStringBuffer, -- * Moving and comparison stepOn, @@ -55,6 +56,7 @@ import GHC.Utils.Encoding import GHC.Utils.IO.Unsafe import GHC.Utils.Panic.Plain import GHC.Utils.Exception ( bracket_ ) +import GHC.Fingerprint import Data.Maybe import System.IO @@ -256,6 +258,13 @@ byteDiff s1 s2 = cur s2 - cur s1 atEnd :: StringBuffer -> Bool atEnd (StringBuffer _ l c) = l == c +-- | Computes a hash of the contents of a 'StringBuffer'. +fingerprintStringBuffer :: StringBuffer -> Fingerprint +fingerprintStringBuffer (StringBuffer buf len cur) = + unsafePerformIO $ + withForeignPtr buf $ \ptr -> + fingerprintData (ptr `plusPtr` cur) len + -- | Computes a 'StringBuffer' which points to the first character of the -- wanted line. Lines begin at 1. atLine :: Int -> StringBuffer -> Maybe StringBuffer |