Commit 1e6e5669c6229846830f0b497591de4e3cf588eb

Ran Benita 2013-12-14T17:39:11

ast: pack the ParseCommon struct This shows a measurable improvement in memory and performance for free, on 64bit at least. Packing is (or should be) safe in this case. Signed-off-by: Ran Benita <ran234@gmail.com>

diff --git a/src/utils.h b/src/utils.h
index 0f4a388..04fb9c5 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -206,4 +206,10 @@ unmap_file(const char *str, size_t size);
 # define ATTR_NULL_SENTINEL
 #endif /* GNUC >= 4 */
 
+#if (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 295)
+#define ATTR_PACKED  __attribute__((__packed__))
+#else
+#define ATTR_PACKED
+#endif
+
 #endif /* UTILS_H */
diff --git a/src/xkbcomp/ast.h b/src/xkbcomp/ast.h
index 36f777a..489b331 100644
--- a/src/xkbcomp/ast.h
+++ b/src/xkbcomp/ast.h
@@ -143,9 +143,11 @@ expr_op_type_to_string(enum expr_op_type type);
 const char *
 expr_value_type_to_string(enum expr_value_type type);
 
-typedef struct _ParseCommon {
-    enum stmt_type type;
+/* This struct contains fields common to all other AST nodes. It is only
+ * ever embedded in other structs, so save some memory by packing it. */
+typedef struct ATTR_PACKED _ParseCommon  {
     struct _ParseCommon *next;
+    enum stmt_type type;
 } ParseCommon;
 
 typedef struct _IncludeStmt {