]> git.neil.brown.name Git - edlib.git/commitdiff
linecount: simplify count_calculate()
authorNeilBrown <neil@brown.name>
Fri, 2 Jun 2023 22:04:59 +0000 (08:04 +1000)
committerNeilBrown <neil@brown.name>
Wed, 28 Jun 2023 05:40:21 +0000 (15:40 +1000)
There is no need to make a special case of m being after end, because m
is always at the start of the file.

Signed-off-by: NeilBrown <neil@brown.name>
lib-linecount.c

index 9983c76679d85cfbfedc2ba5ce9239f6568398f0..df1c10125f7755195d38547b8e18159cb9387e02 100644 (file)
@@ -6,10 +6,11 @@
  *
  * This module can be attached to a Document to count lines/words/chars.
  *
- * It attaches active marks every 100 lines or so and records the
- * counts between the marks.  These are stored as attributes
- * 'lines' 'words' 'chars'.
- * When a change is notified, the attributes are cleared.
+ * It attaches an active mark at the start, then one every 100 lines or so
+ * and records the counts between the marks.  These are stored as attributes
+ * 'lines' 'words' 'chars' on the mark at the start of the range.
+ * When a change is notified, the attributes one the preceeding
+ * mark are cleared.
  * When a count is requested, all marks from top-of-file to target
  * are examined.  If attributes are not present they are calculated.
  * Then they are summed.
@@ -21,7 +22,7 @@
  *
  * When CountLines is called on a doc-pane, pane attributes are set
  * to record the number of lines, words, chars.
- * When it is calld on a mark in the pane attributes are set on the
+ * When it is called on a mark in the pane, attributes are set on the
  * mark to indicate the line, work and char where the mark is.
  * These are always at least 1.
  */
@@ -146,16 +147,7 @@ static void count_calculate(struct pane *p safe,
                /* need to update this one */
                do_count(p, m, vmark_next(m), &l, &w, &c, 1);
 
-       /* If 'm' is not before 'end', just count from
-        * start to end.
-        */
-       if (end && m->seq >= end->seq) {
-               do_count(p, m, end, &lines, &words, &chars, 0);
-               goto done;
-       }
-
-       /* OK, 'm' is before 'end'.
-        * Add totals from m and subsequent. Then count to 'end'.
+       /* Add totals from m to before end. Then count to 'end'.
         */
        lines = words = chars = 0;
        while ((m2 = vmark_next(m)) != NULL &&
@@ -179,7 +171,7 @@ static void count_calculate(struct pane *p safe,
                words += w;
                chars += c;
        }
-done:
+
        if (end) {
                struct attrset **attrs = &end->attrs;
                attr_set_int(attrs, "line", lines + 1);