Last active
June 29, 2016 08:42
-
-
Save mattn/77d3c09e1b193b8d1ddaef86961483f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/bench.c b/bench.c | |
index 5f107c8..a18e099 100644 | |
--- a/bench.c | |
+++ b/bench.c | |
@@ -55,6 +55,7 @@ int main(void) { | |
} | |
static void simple_escape_html(char *dst, const char *input, size_t input_size) { | |
+#if 0 | |
for (int i = 0; i < input_size; i++) { | |
const char c = *(input++); | |
switch (c) { | |
@@ -102,5 +103,27 @@ static void simple_escape_html(char *dst, const char *input, size_t input_size) | |
} | |
} | |
*dst++ = *"\0"; | |
+#endif | |
+ const char *ptr = input, *end = input + input_size; | |
+#define STRCPY(d,s) memcpy(d,s,sizeof(s)-1); d += sizeof(s)-1; | |
+ while (ptr < end) { | |
+ if (*ptr < 48) { | |
+ switch (*ptr) { | |
+ case '&': STRCPY(dst,"&"); break; | |
+ case '>': STRCPY(dst,">"); break; | |
+ case '<': STRCPY(dst,"<"); break; | |
+ case '"': STRCPY(dst,"""); break; | |
+ case '\'': STRCPY(dst,"'"); break; | |
+ case '`': STRCPY(dst,"`"); break; | |
+ case '{': STRCPY(dst,"{"); break; | |
+ case '}': STRCPY(dst,"}"); break; | |
+ default: *dst++ = *ptr; break; | |
+ } | |
+ ptr++; | |
+ } else | |
+ *dst++ = *ptr++; | |
+ } | |
+#undef STRCPY | |
+ *dst++ = 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment