[Gridflow-cvs] [svn] commit: r6804 - in /trunk/src: classes1.cxx classes3.cxx gridflow.cxx gridflow.hxx mmx.rb

svn-gridflow at artengine.ca svn-gridflow at artengine.ca
Sun Nov 6 15:02:44 EST 2011


Author: matju
Date: Sun Nov  6 15:02:44 2011
New Revision: 6804

Log:
faster lookup of Numops and Numbertype (mostly helps [#expr])

Modified:
    trunk/src/classes1.cxx
    trunk/src/classes3.cxx
    trunk/src/gridflow.cxx
    trunk/src/gridflow.hxx
    trunk/src/mmx.rb

Modified: trunk/src/classes1.cxx
==============================================================================
--- trunk/src/classes1.cxx (original)
+++ trunk/src/classes1.cxx Sun Nov  6 15:02:44 2011
@@ -988,7 +988,7 @@
 
 \end class {install("#redim",2,1); add_creator("@redim");}
 
-#define OP(x) dynamic_cast<Numop2 *>(op_dict[string(#x)])
+#define OP(x) dynamic_cast<Numop2 *>(op_dict[gensym(#x)])
 void startup_classes1 () {
 	op_add = OP(+);
 	op_sub = OP(-);

Modified: trunk/src/classes3.cxx
==============================================================================
--- trunk/src/classes3.cxx (original)
+++ trunk/src/classes3.cxx Sun Nov  6 15:02:44 2011
@@ -1345,6 +1345,7 @@
 	int n;
 	P<Grid> a;
 	\attr NumberTypeE cast;
+	\attr t_atom2 when; // FUTURE USE
 	\constructor (t_atom2 d=2, NumberTypeE nt=int32_e) {
 		Dim dim;
 		if (d.a_type==A_LIST) {
@@ -1419,7 +1420,7 @@
 static CONSTRAINT(expect_min_one_dim) {
 	if (d.n<1) RAISE("expecting at least one dimension, got %s",d.to_s());}
 
-#define OP(x) dynamic_cast<Numop2 *>(op_dict[string(#x)])
+#define OP(x) dynamic_cast<Numop2 *>(op_dict[gensym(#x)])
 \class GridClusterAvg {
 	\attr int numClusters;
 	\attr P<Grid> r;

Modified: trunk/src/gridflow.cxx
==============================================================================
--- trunk/src/gridflow.cxx (original)
+++ trunk/src/gridflow.cxx Sun Nov  6 15:02:44 2011
@@ -242,9 +242,8 @@
 
 Numop *convert(const t_atom2 &x, Numop **bogus) {
 	if (x.a_type!=A_SYMBOL) RAISE("expected numop (as symbol)");
-	string k = string(x.a_symbol->s_name);
-	typeof(op_dict.begin()) found = op_dict.find(k);
-	if (found==op_dict.end()) RAISE("expected numop name, not '%s'", k.data());
+	typeof(op_dict.begin()) found = op_dict.find(x.a_symbol);
+	if (found==op_dict.end()) RAISE("expected numop name, not '%s'", x.a_symbol->s_name);
 	return found->second;
 }
 
@@ -270,14 +269,16 @@
 	return strdup(buf);
 }
 
-NumberTypeE NumberTypeE_find (string s) {
-	if (number_type_dict.find(s)==number_type_dict.end()) RAISE("unknown number type \"%s\"", s.data());
+NumberTypeE NumberTypeE_find (t_symbol *s) {
+	if (number_type_dict.find(s)==number_type_dict.end()) RAISE("unknown number type \"%s\"", s->s_name);
 	return number_type_dict[s]->index;
 }
+
+NumberTypeE NumberTypeE_find (string s) {return NumberTypeE_find(gensym(s.data()));}
 
 NumberTypeE NumberTypeE_find (const t_atom &x) {
 	if (x.a_type!=A_SYMBOL) RAISE("expected number-type (as symbol)");
-	return NumberTypeE_find(string(x.a_symbol->s_name));
+	return NumberTypeE_find(x.a_symbol);
 }
 
 // don't touch.

Modified: trunk/src/gridflow.hxx
==============================================================================
--- trunk/src/gridflow.hxx (original)
+++ trunk/src/gridflow.hxx Sun Nov  6 15:02:44 2011
@@ -33,6 +33,7 @@
 #include <string>
 #include <sstream>
 #include <map>
+#include <ext/hash_map>
 #include <stdlib.h>
 #include <string.h>
 #include <signal.h>
@@ -48,6 +49,7 @@
 
 using std::string;
 using std::map;
+using __gnu_cxx::hash_map; // no match for call to (const __gnu_cxx::hash<string>) (const std::string &)
 using std::vector;
 using std::ostream;
 using std::ostringstream;
@@ -607,9 +609,11 @@
 	}
 };
 
+struct t_symbol_eq {bool operator()(t_symbol *a,t_symbol *b) {return a==b;}};
 extern NumberType number_type_table[];
-extern map<string,NumberType *> number_type_dict;
-extern map<string,Numop *> op_dict;
+extern map<t_symbol *,NumberType *> number_type_dict;
+extern map<t_symbol *,Numop *> op_dict;
+//extern hash_map<t_symbol *,Numop *,__gnu_cxx::hash<t_symbol*>,t_symbol_eq> op_dict;
 
 static inline NumberTypeE convert(const t_atom2 &x, NumberTypeE *bogus) {
 	if (x.a_type!=A_SYMBOL) RAISE("expected number-type, got %s",x.to_s().data()); return NumberTypeE_find(string(x.a_symbol->s_name));}

Modified: trunk/src/mmx.rb
==============================================================================
--- trunk/src/mmx.rb (original)
+++ trunk/src/mmx.rb Sun Nov  6 15:02:44 2011
@@ -161,7 +161,7 @@
 		puts "emms"
 	}
 	$decls << "void #{s}(long,#{type}*,#{type});\n"
-	$install << "((Numop2 *)op_dict[string(\"#{sym}\")])->on_#{type}.map = #{s};\n"
+	$install << "((Numop2 *)op_dict[gensym(\"#{sym}\")])->on_#{type}.map = #{s};\n"
 	$count += 1
 end
 
@@ -203,7 +203,7 @@
 		puts "emms"
 	}
 	$decls << "void #{s}(long,#{type}*,#{type}*);\n"
-	$install << "((Numop2 *)op_dict[string(\"#{sym}\")])->on_#{type}.zip = #{s};\n"
+	$install << "((Numop2 *)op_dict[gensym(\"#{sym}\")])->on_#{type}.zip = #{s};\n"
 	$count += 1
 end
 



More information about the Gridflow-cvs mailing list