sped up jython evaluation by calling function directly instead of invoking parser on string representation of function call
git-svn-id: http://google-refine.googlecode.com/svn/trunk@327 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
ff0049307e
commit
6fba7d1e7f
@ -5,7 +5,9 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.python.core.Py;
|
||||||
import org.python.core.PyException;
|
import org.python.core.PyException;
|
||||||
|
import org.python.core.PyFunction;
|
||||||
import org.python.core.PyNone;
|
import org.python.core.PyNone;
|
||||||
import org.python.core.PyObject;
|
import org.python.core.PyObject;
|
||||||
import org.python.core.PyString;
|
import org.python.core.PyString;
|
||||||
@ -21,7 +23,7 @@ public class JythonEvaluable implements Evaluable {
|
|||||||
String[] lines = s.split("\r\n|\r|\n");
|
String[] lines = s.split("\r\n|\r|\n");
|
||||||
|
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
sb.append("def " + s_functionName + "():");
|
sb.append("def " + s_functionName + "(value, cell, cells, row, rowIndex):");
|
||||||
for (int i = 0; i < lines.length; i++) {
|
for (int i = 0; i < lines.length; i++) {
|
||||||
sb.append("\n " + lines[i]);
|
sb.append("\n " + lines[i]);
|
||||||
}
|
}
|
||||||
@ -31,19 +33,16 @@ public class JythonEvaluable implements Evaluable {
|
|||||||
|
|
||||||
public Object evaluate(Properties bindings) {
|
public Object evaluate(Properties bindings) {
|
||||||
try {
|
try {
|
||||||
for (Object key : bindings.keySet()) {
|
// call the temporary PyFunction directly
|
||||||
String k = (String) key;
|
Object result = ((PyFunction)_engine.get(s_functionName)).__call__(
|
||||||
Object v = bindings.get(k);
|
new PyObject[] {
|
||||||
|
Py.java2py( bindings.get("value") ),
|
||||||
_engine.set(
|
new JythonHasFieldsWrapper((HasFields) bindings.get("cell"), bindings),
|
||||||
k,
|
new JythonHasFieldsWrapper((HasFields) bindings.get("cells"), bindings),
|
||||||
(v instanceof HasFields) ?
|
new JythonHasFieldsWrapper((HasFields) bindings.get("row"), bindings),
|
||||||
new JythonHasFieldsWrapper((HasFields) v, bindings) :
|
Py.java2py( bindings.get("rowIndex") )
|
||||||
v
|
}
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
Object result = _engine.eval(s_functionName + "()");
|
|
||||||
|
|
||||||
return unwrap(result);
|
return unwrap(result);
|
||||||
} catch (PyException e) {
|
} catch (PyException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user