Use fgets_unlocked for faster input stream reading

This commit is contained in:
Rico Tiongson 2019-02-07 04:04:44 +08:00
parent 2028767567
commit c65944eae2

View File

@ -230,10 +230,10 @@ namespace service {
config["down4"].c_str() config["down4"].c_str()
); );
// start reading lines from input one by one // start reading lines from input one by one
static string sentence; static const int MAX_LINE_LENGTH = 256;
static char data[MAX_LINE_LENGTH];
bool flag_begin = false; bool flag_begin = false;
while (getline(cin, sentence)) { while (fgets_unlocked(data, MAX_LINE_LENGTH, stdin) != NULL) {
auto data = sentence.data();
cmatch matches; cmatch matches;
if (!flag_begin) { if (!flag_begin) {
if (regex_match(data, matches, gesture_begin)) { if (regex_match(data, matches, gesture_begin)) {