First off, try to get rid of (old_)/line_buffer completely. - [ ] Do not memcpy the whole line_buffer every time a character is modified. - [ ] Do not diff the whole line_buffer every time a character is modified. - [ ] Use memcpy to shift line_buffer instead of the for loop.