From eea899462d042d52b4827a314ce690d1651a79fa Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Tue, 7 Apr 2026 20:08:09 +0200 Subject: Event hotlinking --- src/ZNC.hs | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'src/ZNC.hs') diff --git a/src/ZNC.hs b/src/ZNC.hs index 36d3d4f..4618025 100644 --- a/src/ZNC.hs +++ b/src/ZNC.hs @@ -4,6 +4,7 @@ module ZNC ( Nick, Event(..), preparseLog, parseLog, parseLogRange, + parseLogTimesOnly, ) where import Control.Applicative @@ -19,8 +20,6 @@ import Data.Text.Encoding qualified as TE import Data.Vector.Storable qualified as VS import Data.Word (Word8, Word32) -import Debug.Trace - import Util @@ -58,6 +57,12 @@ preparseLog = VS.fromList . findLineStarts 0 parseLog :: ByteString -> [(HMS, Event)] parseLog = map parseLogLine . BS8.lines +{-# INLINE parseLogTimesOnly #-} +parseLogTimesOnly :: VS.Vector Word32 -> ByteString -> [HMS] +parseLogTimesOnly linestarts bs = + map (fromRight (HMS 0 0 0) . P.parseOnly parseTOD) $ + splitWithLineStarts 0 linestarts bs + -- (start line, number of lines (default to rest of file)) {-# INLINE parseLogRange #-} parseLogRange :: (Int, Maybe Int) -> VS.Vector Word32 -> ByteString -> [(HMS, Event)] @@ -66,33 +71,27 @@ parseLogRange (startln, mnumln) linestarts topbs = splitted = splitWithLineStarts 0 (VS.slice startln numln linestarts) topbs in -- traceShow ("pLR"::String, splitted) $ map parseLogLine splitted + +{-# INLINE splitWithLineStarts #-} +splitWithLineStarts :: Int -> VS.Vector Word32 -> ByteString -> [ByteString] +splitWithLineStarts idx starts bs + | idx >= VS.length starts = [] + | idx == VS.length starts - 1 = + [BS.takeWhile (\b -> b /= 13 && b /= 10) (BS.drop (at idx) bs)] + | otherwise = + trimCR (BS.drop (at idx) (BS.take (at (idx + 1) - 1) bs)) + : splitWithLineStarts (idx + 1) starts bs where - {-# INLINE splitWithLineStarts #-} - splitWithLineStarts :: Int -> VS.Vector Word32 -> ByteString -> [ByteString] - splitWithLineStarts idx starts bs - | idx >= VS.length starts = [] - | idx == VS.length starts - 1 = - [BS.takeWhile (\b -> b /= 13 && b /= 10) (BS.drop (at idx) bs)] - | otherwise = - trimCR (BS.drop (at idx) (BS.take (at (idx + 1) - 1) bs)) - : splitWithLineStarts (idx + 1) starts bs - where - at i = fromIntegral @Word32 @Int (starts VS.! i) + at i = fromIntegral @Word32 @Int (starts VS.! i) trimCR :: ByteString -> ByteString - trimCR bs = case BS.unsnoc bs of - Just (bs', c) | c == 13 -> bs' - _ -> bs + trimCR b = case BS.unsnoc b of + Just (b', c) | c == 13 -> b' + _ -> b +{-# NOINLINE parseLogLine #-} parseLogLine :: ByteString -> (HMS, Event) -parseLogLine bs = - case parseLogLine' bs of - res@(HMS 0 0 0, ParseError) -> traceShow ("PE" :: String, bs) res - res -> res - -{-# NOINLINE parseLogLine' #-} -parseLogLine' :: ByteString -> (HMS, Event) -parseLogLine' = fromRight (HMS 0 0 0, ParseError) . P.parseOnly parseLine +parseLogLine = fromRight (HMS 0 0 0, ParseError) . P.parseOnly parseLine parseLine :: P.Parser (HMS, Event) parseLine = (,) <$> parseTOD <*> parseEvent -- cgit v1.3