[rkward-cvs] SF.net SVN: rkward: [808] trunk/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Oct 5 10:18:49 UTC 2006


Revision: 808
          http://svn.sourceforge.net/rkward/?rev=808&view=rev
Author:   tfry
Date:     2006-10-05 03:18:43 -0700 (Thu, 05 Oct 2006)

Log Message:
-----------
Remove some unneeded PROTECTs and coercion. Seems to work fine in stress testing.
Unfortunately does not give any measurable performance improvement

Modified Paths:
--------------
    trunk/rkward/TODO
    trunk/rkward/rkward/rbackend/rembedinternal.cpp

Modified: trunk/rkward/TODO
===================================================================
--- trunk/rkward/TODO	2006-10-04 22:48:01 UTC (rev 807)
+++ trunk/rkward/TODO	2006-10-05 10:18:43 UTC (rev 808)
@@ -70,6 +70,10 @@
 		- add virtual rCommandStarted () function, so receivers can find out, when their command becomes active
 	REmbedInternal:
 		- probably we do not need na_double at all (just any NaN) => less confusion
+	RObjectList:
+		- most of the time seems to be spent on lookups of object->item
+			- probably it would be smarter to use a reverse map, as item->object should be mostly GUI bound
+			- also use a QHash (Qt4)
 	Detecting object modifications inside R:
 		- RObjectTables sounds highly interesing. Maybe we can use a transparent table to find out about assignments?
 			- Problem: we can't add this on top of the globalenv () (or at least we're not supposed to)

Modified: trunk/rkward/rkward/rbackend/rembedinternal.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rembedinternal.cpp	2006-10-04 22:48:01 UTC (rev 807)
+++ trunk/rkward/rkward/rbackend/rembedinternal.cpp	2006-10-05 10:18:43 UTC (rev 808)
@@ -379,13 +379,21 @@
 QString *SEXPToStringList (SEXP from_exp, unsigned int *count) {
 	char **strings = 0;
 	
-	SEXP strexp;
-	PROTECT (strexp = coerceVector (from_exp, STRSXP));
-	*count = length (strexp);
-	strings = new char* [length (strexp)];
+	// bad format? coerce the vector first
+	if (TYPEOF (from_exp) != STRSXP) {
+		SEXP strexp;
+		PROTECT (strexp = coerceVector (from_exp, STRSXP));
+		QString *list = SEXPToStringList (strexp, count);
+		UNPROTECT (1);
+		return list;
+	}
+
+	// format already good? Avoid coercion (and associated copying)
+	*count = length (from_exp);
+	strings = new char* [*count];
 	unsigned int i = 0;
 	for (; i < *count; ++i) {
-		SEXP dummy = VECTOR_ELT (strexp, i);
+		SEXP dummy = VECTOR_ELT (from_exp, i);
 
 		if (TYPEOF (dummy) != CHARSXP) {
 			strings[i] = strdup ("not defined");	// can this ever happen?
@@ -400,39 +408,49 @@
 	QString *list = stringsToStringList (strings, i);
 	delete [] strings;
 
-	UNPROTECT (1);	// strexp
-
 	return list;
 }
 
 int *SEXPToIntArray (SEXP from_exp, unsigned int *count) {
 	int *integers;
 
-	SEXP intexp;
-	PROTECT (intexp = coerceVector (from_exp, INTSXP));
-	*count = length (intexp);
+	// bad format? coerce the vector first
+	if (TYPEOF (from_exp) != INTSXP) {
+		SEXP intexp;
+		PROTECT (intexp = coerceVector (from_exp, INTSXP));
+		integers = SEXPToIntArray (intexp, count);
+		UNPROTECT (1);
+		return integers;
+	}
+
+	// format already good? Avoid coercion (and associated copying)
+	*count = length (from_exp);
 	integers = new int[*count];
 	for (unsigned int i = 0; i < *count; ++i) {
-		integers[i] = INTEGER (intexp)[i];
+		integers[i] = INTEGER (from_exp)[i];
 	}
-	UNPROTECT (1);
-
 	return integers;
 }
 
 double *SEXPToRealArray (SEXP from_exp, unsigned int *count) {
 	double *reals;
 
-	SEXP realexp;
-	PROTECT (realexp = coerceVector (from_exp, REALSXP));
-	*count = length (realexp);
+	// bad format? coerce the vector first
+	if (TYPEOF (from_exp) != REALSXP) {
+		SEXP realexp;
+		PROTECT (realexp = coerceVector (from_exp, REALSXP));
+		reals = SEXPToRealArray (realexp, count);
+		UNPROTECT (1);
+		return reals;
+	}
+	
+	// format already good? Avoid coercion (and associated copying)
+	*count = length (from_exp);
 	reals = new double[*count];
 	for (unsigned int i = 0; i < *count; ++i) {
-		reals[i] = REAL (realexp)[i];
+		reals[i] = REAL (from_exp)[i];
 		if (R_IsNaN (reals[i]) || R_IsNA (reals[i]) ) reals[i] = RKGlobals::na_double;
 	}
-	UNPROTECT (1);	// realexp
-
 	return reals;
 }
 
@@ -451,14 +469,15 @@
 			data->datatype = RData::RealVector;
 			break;
 		case VECSXP:
+			count = 0;
 			count = length (from_exp);
 			{
 				RData **structure_array = new RData*[count];
 				for (unsigned int i=0; i < count; ++i) {
-					SEXP subexp;
-					PROTECT (subexp = VECTOR_ELT (from_exp, i));
+					SEXP subexp = VECTOR_ELT (from_exp, i);
+					//PROTECT (subexp);	// should already be protected as part of the parent from_exp
 					structure_array[i] = SEXPToRData (subexp);
-					UNPROTECT (1);
+					//UNPROTECT (1);
 				}
 				data->data = structure_array;
 			}


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list