From 7b6053ed132378402fe5b0ce007e3be9005bcd66 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Wed, 30 May 2018 20:29:18 -0400 Subject: [PATCH] Don't pyimport repr multiple times --- src/pyodide.js | 11 ----------- src/pyproxy.c | 7 ++++--- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/pyodide.js b/src/pyodide.js index 986829cd9..fc60277bd 100644 --- a/src/pyodide.js +++ b/src/pyodide.js @@ -75,16 +75,6 @@ var languagePluginLoader = new Promise((resolve, reject) => { return promise; }; - //////////////////////////////////////////////////////////// - // Callable Python object shim - let makeCallableProxy = (obj) => { - var clone = obj.clone(); - function callProxy(args) { - return clone.call(Array.from(arguments), {}); - }; - return callProxy; - }; - //////////////////////////////////////////////////////////// // Loading Pyodide let wasmURL = `${baseURL}pyodide.asm.wasm`; @@ -112,7 +102,6 @@ var languagePluginLoader = new Promise((resolve, reject) => { script.onload = () => { window.pyodide = pyodide(Module); window.pyodide.loadPackage = loadPackage; - window.pyodide.makeCallableProxy = makeCallableProxy; }; document.head.appendChild(script); }; diff --git a/src/pyproxy.c b/src/pyproxy.c index cb2e96c1b..d3c961aa9 100644 --- a/src/pyproxy.c +++ b/src/pyproxy.c @@ -127,9 +127,10 @@ EM_JS(int, pyproxy_init, (), { get: function (jsobj, jskey) { if (jskey === 'toString') { return function() { - // TODO: Cache repr - var repr = pyodide.pyimport('repr'); - return repr(jsobj); + if (window.pyodide.repr === undefined) { + window.pyodide.repr = window.pyodide.pyimport('repr'); + } + return window.pyodide.repr(jsobj); } } else if (jskey === '$$') { return jsobj['$$'];