Mini-refactoring prompted by https://phabricator.fb.com/D1770460
authorAndrei Alexandrescu <aalexandre@fb.com>
Thu, 8 Jan 2015 18:59:51 +0000 (10:59 -0800)
committerViswanath Sivakumar <viswanath@fb.com>
Tue, 13 Jan 2015 19:01:05 +0000 (11:01 -0800)
Summary: I got obliged into this one :o).

Test Plan: runtests

Reviewed By: meyering@fb.com

Subscribers: njormrod, folly-diffs@

FB internal diff: D1772328

Signature: t1:1772328:1420744114:2b81e46d77800d247293cb667bbef86e9d6d4755

folly/FBString.h

index e3f86b293418d3e975f8d6ea8d01edc42cc1b69d..b866b901049aa473e9616883ecc6d8aaf78121e8 100644 (file)
@@ -2322,17 +2322,16 @@ std::basic_istream<
       n = str.max_size();
     }
     str.erase();
-    auto got = is.rdbuf()->sgetc();
-    for (; extracted != size_t(n) && got != T::eof() &&
-           !isspace(got); ++extracted) {
-      // Whew. We get to store this guy
+    for (auto got = is.rdbuf()->sgetc(); extracted != size_t(n); ++extracted) {
+      if (got == T::eof()) {
+        err |= __ios_base::eofbit;
+        is.width(0);
+        break;
+      }
+      if (isspace(got)) break;
       str.push_back(got);
       got = is.rdbuf()->snextc();
     }
-    if (got == T::eof()) {
-      err |= __ios_base::eofbit;
-      is.width(0);
-    }
   }
   if (!extracted) {
     err |= __ios_base::failbit;