shithub: pprolog

Download patch

ref: 0a706b5b413aa96a944f45f28fb948c62e763555
parent: ef55dad27294cc01671d3c7b0f8091968dc72884
author: Peter Mikkelsen <peter@pmikkelsen.com>
date: Sat Jul 24 10:44:07 EDT 2021

Reduce size of the Term struct from about 72 bytes to 48

--- a/dat.h
+++ b/dat.h
@@ -18,18 +18,25 @@
 	Operator *next;
 };
 
-struct Term
+struct Compound
 {
-	int tag;
-
 	Rune *text;
 	int arity;
-	Term *next;
 	Term *children;
-	vlong ival;
-	double dval;
+};
+
+struct Term
+{
+	u8int tag;
+	u8int inparens;
 	uvlong clausenr;
-	int inparens; /* kinda bad hack needed for the current parser */
+	Term *next;
+
+	union {
+		vlong ival;
+		double dval;
+		struct Compound;
+	};
 };
 
 struct Binding
--- a/parser.c
+++ b/parser.c
@@ -211,8 +211,8 @@
 	OpInfo *infos = gmalloc(sizeof(OpInfo) * length);
 
 	for(i = 0, t = list; i < length; i++){
-		Operator *op = getoperator(t->text, currentmod);
-		if(op && t->tag == AtomTerm && !t->inparens){
+		Operator *op;
+		if(t->tag == AtomTerm && !t->inparens && (op = getoperator(t->text, currentmod))){
 			infos[i].type = op->type;
 			infos[i].level = op->level;
 		}else{