From 1814b50d5b96a3ddbf5fe1e3c8e781c53ac747c4 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 28 Aug 2018 08:54:05 +0200 Subject: HeadphoneKey(runAction): Use `while` loop over `result->action` Using `strlen` loops once over the string, so along with our `for` loop, we have two loops over the string. No big deal since these shouldn't be that long. But, using a `while` loop we can iterate just once. Reference: Alexandre C. (https://stackoverflow.com/users/373025/alexandre-c) https://stackoverflow.com/questions/3213827/how-to-iterate-over-a-string-in-c/3213903#3213903 --- DomeKey/HeadphoneKey.m | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/DomeKey/HeadphoneKey.m b/DomeKey/HeadphoneKey.m index 1d5811b..515b7de 100644 --- a/DomeKey/HeadphoneKey.m +++ b/DomeKey/HeadphoneKey.m @@ -77,9 +77,12 @@ const CKeyActionResult *result = c_run_key_action(trigger, count); if (*result->kind == MapKind_Map) { - size_t length = strlen(result->action); - for (size_t i = 0; i < length; i++) { + const char *c = result->action; + int i = 0; + while (*c) { [KeyboardSimulator simpleKeyPressWithKey:result->action[i]]; + i++; + *c++; } } -- cgit v1.2.3