cs50 / libcs50

This is CS50's Library for C.
https://cs50.readthedocs.io/libraries/cs50/c/
GNU General Public License v3.0
1.66k stars 831 forks source link

Improved a slight inefficiency when reallocating #306

Closed 9x14S closed 9 months ago

9x14S commented 9 months ago

The inefficiency lies at the repeated calling of realloc() to make space for each character read just for the buffer to be minimized at the end.

dmalan commented 9 months ago

This is deliberate, actually. We used to allocate more bytes at a time but decided to simplify the code, particularly since the human is the bottleneck with get_string, not the underlying system calls.

As written, too, looks like this PR risks overflowing capacity, fyi!