From c65944eae2efd5f066d67bed8e1d686290977ab5 Mon Sep 17 00:00:00 2001 From: Rico Tiongson Date: Thu, 7 Feb 2019 04:04:44 +0800 Subject: [PATCH] Use fgets_unlocked for faster input stream reading --- src/comfortable-swipe.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/comfortable-swipe.cpp b/src/comfortable-swipe.cpp index bdee842..a4843db 100644 --- a/src/comfortable-swipe.cpp +++ b/src/comfortable-swipe.cpp @@ -230,10 +230,10 @@ namespace service { config["down4"].c_str() ); // 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; - while (getline(cin, sentence)) { - auto data = sentence.data(); + while (fgets_unlocked(data, MAX_LINE_LENGTH, stdin) != NULL) { cmatch matches; if (!flag_begin) { if (regex_match(data, matches, gesture_begin)) {