Compile regex outside of buffer function to avoid runtime hiccup

This commit is contained in:
Rico Tiongson 2019-02-07 02:12:19 +08:00
parent 1079d0afe2
commit cdaa98abe1

View File

@ -206,14 +206,17 @@ namespace service {
} }
namespace service { namespace service {
// process regex at compile time
const regex gesture_begin(util::GESTURE_SWIPE_BEGIN_REGEX_PATTERN);
const regex gesture_update(util::GESTURE_SWIPE_UPDATE_REGEX_PATTERN);
const regex gesture_end(util::GESTURE_SWIPE_END_REGEX_PATTERN);
// parses output from libinput debug-events // parses output from libinput debug-events
void buffer() { void buffer() {
// check first if $user // check first if $user
ios::sync_with_stdio(false); ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0); cin.tie(0); cout.tie(0);
const regex gesture_begin(util::GESTURE_SWIPE_BEGIN_REGEX_PATTERN);
const regex gesture_update(util::GESTURE_SWIPE_UPDATE_REGEX_PATTERN);
const regex gesture_end(util::GESTURE_SWIPE_END_REGEX_PATTERN);
string sentence; string sentence;
// read config file // read config file
auto config = util::read_config_file(conf_filename().data()); auto config = util::read_config_file(conf_filename().data());
@ -252,7 +255,7 @@ namespace service {
} }
// starts service // starts service
void start() { void start() {
int x = system("stdbuf -oL -e0 libinput debug-events | " PROGRAM " buffer"); int x = system("stdbuf -oL -eL libinput debug-events | " PROGRAM " buffer");
} }
// stops service // stops service
void stop() { void stop() {
@ -380,14 +383,14 @@ namespace util {
* fingers dx dy udx udy * fingers dx dy udx udy
*/ */
const char* GESTURE_SWIPE_UPDATE_REGEX_PATTERN = const char* GESTURE_SWIPE_UPDATE_REGEX_PATTERN =
"^\\s*" // trim start of string "^\\s*" // trim start of string
"\\s+event\\d+" // event "\\s+event\\d+" // event
"\\s+GESTURE_SWIPE_UPDATE" // gesture "\\s+GESTURE_SWIPE_UPDATE" // gesture
"\\s+\\S+" // timestamp "\\s+\\S+" // timestamp
"\\s+(\\d+)" // fingers "\\s+(\\d+)" // fingers
"\\s+" CF_NUMBER_DIVISION // speed (dx/dy) "\\s+" CF_NUMBER_DIVISION // speed (dx/dy)
"\\s+\\(" CF_NUMBER_DIVISION "\\s+unaccelerated\\)" // unaccelerated speed (udx/udy) "\\s+\\(" CF_NUMBER_DIVISION "\\s+unaccelerated\\)" // unaccelerated speed (udx/udy)
"\\s*$" // trim end of string "\\s*$" // trim end of string
; ;
// delete macros // delete macros