In the process of combing through Stdio.FILE, I found 2 bugs (fixes already committed), and one small optimisation opportunity. Any objections against checking this one in as well (it basically moves some code around, to make getchar() inlinable)?
commit 9c6d0b0b46b53253119390a76883c962be3e2bf2 Author: Stephen R. van den Berg srb@cuci.nl Date: Mon Jul 14 12:47:28 2008 +0200
Make getchar() less filling, and inlinable
diff --git a/lib/modules/Stdio.pmod/module.pmod b/lib/modules/Stdio.pmod/module.pmod index 8edf78b..fa4aacd 100644 --- a/lib/modules/Stdio.pmod/module.pmod +++ b/lib/modules/Stdio.pmod/module.pmod @@ -1897,6 +1897,22 @@ class FILE bpos=0; }
+ private protected final int getchar_get_data() + { + b = ""; + bpos=0; + return low_get_data(); + } + + private protected final void getchar_updatelinecache() + { + if(sizeof(cached_lines)>lp+1 && sizeof(cached_lines[lp])) + cached_lines = ({cached_lines[lp][1..]})+({cached_lines[lp+1]}); + else + cached_lines = ({}); + lp=0; + } + //! This function returns one character from the input stream. //! //! @returns @@ -1905,16 +1921,13 @@ class FILE //! @note //! Returns an @expr{int@} and not a @expr{string@} of length 1. //! - int getchar() + inline int getchar() { - if(sizeof(b) - bpos <= 0 && !get_data()) + if(sizeof(b) - bpos <= 0 && !getchar_get_data()) return -1;
- if(sizeof(cached_lines)>lp+1 && sizeof(cached_lines[lp])) - cached_lines = ({cached_lines[lp][1..]})+({cached_lines[lp+1]}); - else - cached_lines = ({}); - lp=0; + if(sizeof(cached_lines)) + getchar_updatelinecache();
return b[bpos++]; }