bugGNU nano - Bugs: bug #63086, [Task] stop reallocating the...


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

bug #63086: [Task] stop reallocating the keybuffer for every keystroke

Submitter:  Benno Schulenberg <bens>
Submitted:  Wed 21 Sep 2022 07:51:38 AM UTC
Severity:  1 - Wish Status:  Fixed
Assigned to:  bens Open/Closed:  Closed

Fri 30 Sep 2022 09:31:23 AM UTC, comment #2: 

And closing because it was just a small inefficiency, not a bug.

Benno Schulenberg <bens>
Project Administrator
Mon 26 Sep 2022 02:41:20 PM UTC, comment #1: 

Fixed in git, commits 3922b531 and 6fde7d8a, by allocating three small buffers and only ever increasing their size when needed and never freeing them.

The first of those two commits saves lots of calls of nrealloc() when pasting a large piece of text into nano from outside.

Benno Schulenberg <bens>
Project Administrator
Wed 21 Sep 2022 07:51:38 AM UTC, original submission:  

In read_keys_from() in src/winio.c, the keystroke buffer is allocated afresh for every single keystroke, and then extended for every additional key code that we get from whetch() (from an escape sequence, for example).  This is wasteful.  We know that we're going to need room for at least one key code, why not allocate room for say 32 key codes upfront, and keep these allocated always, and only ever extend the keystroke buffer when needed (when the user pastes some piece of text, for example)?  And never shrink the buffer again (why go to the trouble -- most sessions of nano are short, the memory will be freed within a couple of minutes).

The same goes for the 'puddle' in process_a_keystroke() in src/nano.c and the corresponding 'puddle' in src/prompt.c: keep them allocated, and cut out the calls of nrealloc() and free().

(The disadvantage is that for each keybuffer and puddle an extra variable is need to store the allocated size in, and that, whenever adding something to the buffer or puddle, the current size needs to be compared against the allocated size, and when equal, the buffer or puddle needs to be reallocated.)

Benno Schulenberg <bens>
Project Administrator


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

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by bens (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
    2022-09-30 bens Open/ClosedOpen Closed
    2022-09-26 bens StatusIn Progress Fixed
    2022-09-25 bens StatusNone In Progress
        Assigned toNone bens

    Back to the top

    Powered by Savane 3.9