From 1f721c1936cbfb1ea4a742f12754047afdcff3a8 Mon Sep 17 00:00:00 2001 From: Bodigrim Date: Mon, 25 Apr 2022 20:15:01 +0100 Subject: [PATCH] Suggest posLine . lengthAsPosition instead of lengthInLines --- src/Data/Text/Rope.hs | 3 +++ src/Data/Text/Utf16/Rope.hs | 3 +++ src/Data/Text/Utf16/Rope/Mixed.hs | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/Data/Text/Rope.hs b/src/Data/Text/Rope.hs index 596dcfd..cc5c658 100644 --- a/src/Data/Text/Rope.hs +++ b/src/Data/Text/Rope.hs @@ -248,6 +248,9 @@ lastChar = \case -- >>> lengthInLines "foo\nbar" -- 2 -- +-- If you do not care about ignoring the last newline character, +-- you can use 'posLine' . 'lengthAsPosition' instead, which works in O(1). +-- lengthInLines :: Rope -> Word lengthInLines rp = case lastChar rp of Nothing -> 0 diff --git a/src/Data/Text/Utf16/Rope.hs b/src/Data/Text/Utf16/Rope.hs index b7cc687..9128835 100644 --- a/src/Data/Text/Utf16/Rope.hs +++ b/src/Data/Text/Utf16/Rope.hs @@ -247,6 +247,9 @@ lastChar = \case -- >>> lengthInLines "foo\nbar" -- 2 -- +-- If you do not care about ignoring the last newline character, +-- you can use 'posLine' . 'lengthAsPosition' instead, which works in O(1). +-- lengthInLines :: Rope -> Word lengthInLines rp = case lastChar rp of Nothing -> 0 diff --git a/src/Data/Text/Utf16/Rope/Mixed.hs b/src/Data/Text/Utf16/Rope/Mixed.hs index 6da8d9c..a87f127 100644 --- a/src/Data/Text/Utf16/Rope/Mixed.hs +++ b/src/Data/Text/Utf16/Rope/Mixed.hs @@ -285,6 +285,9 @@ lastChar = \case -- >>> lengthInLines "foo\nbar" -- 2 -- +-- If you do not care about ignoring the last newline character, +-- you can use 'Char.posLine' . 'charLengthAsPosition' instead, which works in O(1). +-- lengthInLines :: Rope -> Word lengthInLines rp = case lastChar rp of Nothing -> 0