[Python-checkins] python/dist/src/Objects longobject.c,1.120,1.121

Neal Norwitz neal@metaslash.com
Sun, 11 Aug 2002 23:49:42 -0400


tim_one@users.sourceforge.net wrote:

> Lots of things were changed from that.  This needs a lot more testing,
> for correctness and speed, the latter especially when bit lengths are

> + static PyObject *
> + long_mul(PyLongObject *v, PyLongObject *w)
> + {
	  /* snip */
> +       if (Py_GETENV("KARAT") != NULL)
> +               z = k_mul(a, b);
> +       else
> +               z = x_mul(a, b);

Py_GETENV could be a speed problem.  getenv() can be very slow
on some boxes (linear lookup in the env't).  It would probably 
be best to cache the env value of KARAT or store the function.
Something like:

	typedef PyLongObject*(mul_func_t)(PyLongObject *a, PyLongObject *b);
	static mul_func_t mul_func;
	if (mul_func == NULL)
	{
	       if (Py_GETENV("KARAT") != NULL)
	               mul_func = k_mul;
	       else
	               mul_func = x_mul;
	}

Of course, this means, KARAT must be set prior to the first call to long_mul
and cannot be changed thereafter.

I'll try to make some tests and use valgrind.

Neal