patchGNU nano - Patches: patch #9267, fix an inefficiency in...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #9267: fix an inefficiency in display_string()

Submitter:  David Lawrence Ramsey <dolorous>
Submitted:  Thu 23 Feb 2017 04:55:29 PM UTC
   
 
Priority:  5 - Normal Status:  Done
Privacy:  Public Assigned to:  dolorous
Open/Closed:  Closed Release:  None

Fri 24 Feb 2017 08:54:24 PM UTC, comment #3: 

No problem.  And yes, mb_cur_max() should be 4; I was thinking MB_CUR_MAX.

David Lawrence Ramsey <dolorous>
Group Member
Fri 24 Feb 2017 10:14:40 AM UTC, comment #2: 

Thanks for the patch.  A tweaked version was pushed, f1d214c0.

About skipping the extra bytes for invalid codepoints: it's an ugly special case.  See length_of_char() in chars.c: when the codepoint is invalid, it subtracts 8 from the length, to make it well-and-good negative, so this can be noticed later, so that the entire codepoint can be skipped at once: by adding the "charlength" plus 8, minus the 1 that was already added by buf++.  Yes, as I said: it's ugly.

(But mb_cur_max() should normally be 4 when using UTF8, no?)

Benno Schulenberg <bens>
Group administrator
Thu 23 Feb 2017 08:27:40 PM UTC, comment #1: 

As long as I'm looking at this, as an aside, there's also this bit of code near the end of display_string(), which you added in commit 0894587:

        /* For invalid codepoints, skip extra bytes. */
        if (charlength < -1)
           buf += charlength + 7;

What exactly does the 7 refer to?  Considering the surrounding code, it looks like it should be (mb_cur_max() + 1), since mb_cur_max() is 6.

David Lawrence Ramsey <dolorous>
Group Member
Thu 23 Feb 2017 04:55:29 PM UTC, original submission:  

In current git, in display_string(), converted is allocated space for the entire buffer (also involving a strlen(), so the entire string is scanned).  However, immediately afterwards, the buffer is shifted forward to start_index and displayed from there; nothing before start_index is looked at again past that point.

So, if I'm reading the code correctly, the allocation of converted could be moved down to just after the point where the buffer is shifted forward, to avoid using more space or doing more scanning than necessary.  The attached patch does this.

David Lawrence Ramsey <dolorous>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bens (Posted a comment)
  • -email is unavailable- added by dolorous (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-04-02 bens Open/ClosedOpen Closed
    2017-02-24 bens StatusNone Done
        Assigned toNone dolorous
    2017-02-23 dolorous Attached File- Added 0001-tweaks-fix-an-inefficiency-in-display_string.patch, #39815

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code