Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions flang-rt/include/flang-rt/runtime/io-stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ class IoStatementState {
: connection_{connection} {}
RT_API_ATTRS FastAsciiField(
ConnectionState &connection, const char *start, std::size_t bytes)
: connection_{connection}, at_{start}, limit_{start + bytes} {
CheckForAsterisk();
}
: connection_{connection}, at_{start}, limit_{start + bytes} {}
RT_API_ATTRS ConnectionState &connection() { return connection_; }
RT_API_ATTRS std::size_t got() const { return got_; }

Expand All @@ -168,7 +166,6 @@ class IoStatementState {
if (at_) {
if (std::size_t bytes{io.GetNextInputBytes(at_)}) {
limit_ = at_ + bytes;
CheckForAsterisk();
} else {
at_ = limit_ = nullptr;
}
Expand All @@ -181,19 +178,28 @@ class IoStatementState {
}
connection_.HandleRelativePosition(bytes);
}
RT_API_ATTRS bool MightHaveAsterisk() const { return !at_ || hasAsterisk_; }

private:
RT_API_ATTRS void CheckForAsterisk() {
hasAsterisk_ = at_ && at_ < limit_ &&
runtime::memchr(at_, '*', limit_ - at_) != nullptr;
// Could there be a list-directed repetition count here?
RT_API_ATTRS bool MightBeRepetitionCount() const {
if (!at_) {
return true; // must use slow path for internal KIND/=1 input
} else {
if (const char *p{at_}; *p >= '0' && *p <= '9') {
while (++p < limit_) {
if (*p < '0' || *p > '9') {
return *p == '*';
}
}
}
return false;
}
}

private:
ConnectionState &connection_;
const char *at_{nullptr};
const char *limit_{nullptr};
std::size_t got_{0}; // for READ(..., SIZE=)
bool hasAsterisk_{false};
};

RT_API_ATTRS FastAsciiField GetUpcomingFastAsciiField();
Expand Down
4 changes: 2 additions & 2 deletions flang-rt/lib/runtime/io-stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,8 +905,8 @@ ListDirectedStatementState<Direction::Input>::GetNextDataEdit(
if (imaginaryPart_) { // can't repeat components
return edit;
}
if (*ch >= '0' && *ch <= '9' && fastField.MightHaveAsterisk()) {
// look for "r*" repetition count
if (*ch >= '0' && *ch <= '9' && fastField.MightBeRepetitionCount()) {
// There's decimal digits followed by '*'.
auto start{fastField.connection().positionInRecord};
int r{0};
do {
Expand Down
Loading