@@ -184,6 +184,18 @@ class IoStatementState {
184184 }
185185 connection_.HandleRelativePosition (bytes);
186186 }
187+ RT_API_ATTRS bool SkipBlanks () {
188+ if (at_) {
189+ const char *start{at_};
190+ while (at_ < limit_ && (*at_ == ' ' || *at_ == ' \t ' || *at_ == ' \n ' )) {
191+ ++at_;
192+ }
193+ connection_.HandleRelativePosition (at_ - start);
194+ return true ;
195+ } else {
196+ return false ;
197+ }
198+ }
187199
188200 // Could there be a list-directed repetition count here?
189201 RT_API_ATTRS bool MightBeRepetitionCount () const {
@@ -289,24 +301,32 @@ class IoStatementState {
289301 // Skips spaces, advances records, and ignores NAMELIST comments
290302 RT_API_ATTRS common::optional<char32_t > GetNextNonBlank (
291303 std::size_t &byteCount, FastAsciiField *fastField = nullptr ) {
292- auto ch{GetCurrentChar (byteCount, fastField)};
293304 bool inNamelist{mutableModes ().inNamelist };
305+ if (fastField) {
306+ while (fastField->SkipBlanks ()) {
307+ if (auto ch{fastField->Next ()}) {
308+ if (inNamelist && *ch == ' !' ) {
309+ // skip namelist comment
310+ } else {
311+ byteCount = 1 ;
312+ return ch;
313+ }
314+ }
315+ if (!AdvanceRecord ()) {
316+ break ;
317+ }
318+ fastField->NextRecord (*this );
319+ }
320+ }
321+ auto ch{GetCurrentCharSlow (byteCount)};
294322 while (!ch || *ch == ' ' || *ch == ' \t ' || *ch == ' \n ' ||
295323 (inNamelist && *ch == ' !' )) {
296324 if (ch && (*ch == ' ' || *ch == ' \t ' || *ch == ' \n ' )) {
297- if (fastField) {
298- fastField->Advance (0 , byteCount);
299- } else {
300- HandleRelativePosition (byteCount);
301- }
302- } else if (AdvanceRecord ()) {
303- if (fastField) {
304- fastField->NextRecord (*this );
305- }
306- } else {
325+ HandleRelativePosition (byteCount);
326+ } else if (!AdvanceRecord ()) {
307327 return common::nullopt ;
308328 }
309- ch = GetCurrentChar (byteCount, fastField );
329+ ch = GetCurrentCharSlow (byteCount);
310330 }
311331 return ch;
312332 }
0 commit comments