shithub: mc

Download patch

ref: cd1b25a6047e4ed9bf368811b6a4f7e3d18b88f9
parent: 5b7e3296ba57c446904ecd173ad9f3823a119851
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Feb 27 19:11:42 EST 2016

Don't recompute 'hasparams' over and over.

--- a/parse/parse.h
+++ b/parse/parse.h
@@ -112,9 +112,6 @@
 	Srcloc loc;
 	Vis vis;
 
-	int resolved; /* Have we resolved the subtypes? Prevents infinite recursion. */
-	int fixed;	/* Have we fixed the subtypes? Prevents infinite recursion. */
-
 	Bitset *traits;	/* the type constraints matched on this type */
 	Node **traitlist;  /* The names of the constraints on the type. Used to fill the bitset */
 	size_t ntraitlist; /* The length of the constraint list above */
@@ -137,12 +134,16 @@
 		Ucon **udecls; /* Tyunion: decls in union */
 	};
 
-	char issynth;	/* Tyname: whether this is synthesized or not */
+	char hasparams;	 /* cache for whether this type has params */
+	char issynth;	 /* Tyname: whether this is synthesized or not */
 	char ishidden;   /* Tyname: whether this is hidden or not */
 	char ispkglocal; /* Tyname: whether this is package local or not */
 	char isimport;   /* Tyname: whether tyis type was imported. */
 	char isreflect;  /* Tyname: whether this type has reflection info */
 	char isemitted;  /* Tyname: whether this type has been emitted */
+	char resolved; /* Have we resolved the subtypes? Prevents infinite recursion. */
+	char fixed;	/* Have we fixed the subtypes? Prevents infinite recursion. */
+
 };
 
 struct Ucon {
--- a/parse/type.c
+++ b/parse/type.c
@@ -401,12 +401,13 @@
 int hasparams(Type *t)
 {
 	Bitset *visited;
-	int r;
 
+	if (t->hasparams)
+		return 1;
 	visited = mkbs();
-	r = hasparamsrec(t, visited);
+	t->hasparams = hasparamsrec(t, visited);
 	bsfree(visited);
-	return r;
+	return t->hasparams;
 }
 
 Type *tybase(Type *t)