From aad85151ae7ad79cca644550cd73006006108ae9 Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Tue, 22 Mar 2005 01:25:34 +0000
Subject: [PATCH] in do_justify(), instead of breaking a line at a space and
 readding the space afterwards, just break the line after the space, as it's
 more efficient

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2412 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog  |  4 ++++
 src/nano.c | 18 ++++++------------
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5b852fa4..f167df34 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -21,6 +21,10 @@ CVS code -
 	- Fix erroneous #ifdef that resulted in the -d/--rebinddelete
 	  and -k/--cut options' not being printed when NANO_SMALL was
 	  defined. (DLR)
+  do_justify()
+	- Instead of breaking a line at a space and readding the space
+	  afterwards, just break the line after the space, as it's more
+	  efficient. (DLR)
 - utils.c:
   regexec_safe()
 	- Rename to safe_regexec() for consistency. (DLR)
diff --git a/src/nano.c b/src/nano.c
index 24b8ae40..1f805ec9 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -3114,8 +3114,9 @@ void do_justify(bool full_justify)
 
 	    assert(break_pos < line_len);
 
-	    /* Make a new line and copy the text after where we broke
-	     * this line to the beginning of the new line. */
+	    /* Make a new line, and copy the text after where we're
+	     * going to break this line to the beginning of the new
+	     * line. */
 	    splice_node(current, make_new_node(current), current->next);
 
 	    /* If this paragraph is non-quoted, and autoindent isn't
@@ -3136,7 +3137,7 @@ void do_justify(bool full_justify)
 
 	    par_len++;
 	    totlines++;
-	    totsize += indent_len;
+	    totsize += indent_len + 1;
 
 #ifndef NANO_SMALL
 	    /* Adjust the mark coordinates to compensate for the change
@@ -3147,15 +3148,8 @@ void do_justify(bool full_justify)
 	    }
 #endif
 
-	    /* Break the line, and add the space back to where we broke
-	     * it. */
-	    null_at(&current->data, break_pos);
-
-	    current->data = charealloc(current->data, break_pos + 2);
-	    current->data[break_pos] = ' ';
-	    current->data[break_pos + 1] = '\0';
-
-	    totsize++;
+	    /* Break the line at the character just after the space. */
+	    null_at(&current->data, break_pos + 1);
 
 	    /* Go to the next line. */
 	    par_len--;
-- 
GitLab