Improve performance of perform_rebinding_with_section
This function was using a full strlen check just to check that the
length was greater than 1 so it could index into position 1. I noticed
that this was pretty slow on iPhone 4, so wrote a little function that
just checks that the string is longer than the given value, then
returns.
diff --git a/fishhook.c b/fishhook.c
index 903d74f..405053a 100644
--- a/fishhook.c
+++ b/fishhook.c
@@ -76,6 +76,15 @@
return 0;
}
+static bool str_longer(const char *symbol, size_t len) {
+ for (size_t i = 0; i <= len; i++) {
+ if (symbol[i] == 0) {
+ return false;
+ }
+ }
+ return true;
+}
+
static void perform_rebinding_with_section(struct rebindings_entry *rebindings,
section_t *section,
intptr_t slide,
@@ -95,7 +104,7 @@
struct rebindings_entry *cur = rebindings;
while (cur) {
for (uint j = 0; j < cur->rebindings_nel; j++) {
- if (strlen(symbol_name) > 1 &&
+ if (str_longer(symbol_name, 1) &&
strcmp(&symbol_name[1], cur->rebindings[j].name) == 0) {
if (cur->rebindings[j].replaced != NULL &&
indirect_symbol_bindings[i] != cur->rebindings[j].replacement) {