cs50 / libcs50

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

Improved a slight inefficiency when reallocating #306

Closed 9x14S closed 1 year ago

9x14S commented 1 year 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 1 year 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!