patch 9.1.0256: Finding autocmd events is inefficient

Problem:  Finding autocmd events is inefficient
Solution: Use binary search to find events, cache last found events,
          avoid use of strlen(), add SessionWritePost autocmd,
          fix test_codestyle and avoid endless loop
          (John Marriott)

closes: #14287

Signed-off-by: John Marriott <basilisk@internode.on.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/structs.h b/src/structs.h
index 2218de7..3ce13ff 100644
--- a/src/structs.h
+++ b/src/structs.h
@@ -5060,3 +5060,18 @@
     linenr_T	spv_capcol_lnum;    // line number for "cap_col"
 #endif
 } spellvars_T;
+
+// Return the length of a string literal
+#define STRLEN_LITERAL(s) (sizeof(s) - 1)
+
+// Store a key/value pair
+typedef struct
+{
+    int	    key;        // the key
+    char    *value;     // the value string
+    size_t  length;     // length of the value string
+} keyvalue_T;
+
+#define KEYVALUE_ENTRY(k, v) \
+    {(k), (v), STRLEN_LITERAL(v)}
+