------- Comment #4 from tstarling at wikimedia dot org  2010-09-07 17:18 -------
Benchmarking on Solaris indicates that cin.getline() takes only 1us per
iteration there, but I don't think the source code is available, so it's hard
to provide details. 

However, I think that a huge speedup could be achieved by making
basic_istream<char>::getline() into a simple wrapper around a GNU-specific
virtual function in basic_streambuf. This would allow it to be specialised in
stdio_sync_filebuf, where it could be implemented using fgets() or getdelim()
instead of getc(). 

This would have the additional positive impact of making it atomic. Currently,
cin.getline() does not properly lock the underlying libc stream with
flockfile(). This means that if one thread is calling cin.getline(), and
another thread is calling getc(), then cin.getline() may return mangled partial
lines due to interleaved calls to getc() from the other thread.



Reply via email to