[Python-checkins] r68868 - python/branches/py3k/Modules/_pickle.c

Neal Norwitz nnorwitz at gmail.com
Fri Jan 23 06:26:14 CET 2009


On Thu, Jan 22, 2009 at 8:43 PM, alexandre. vassalotti
<python-checkins at python.org> wrote:
> Author: alexandre.vassalotti
> Date: Fri Jan 23 05:43:46 2009
> New Revision: 68868
>
> Log:
> Remove unnecessary copying in load_long().
>
>
> Modified:
>   python/branches/py3k/Modules/_pickle.c
>
> Modified: python/branches/py3k/Modules/_pickle.c
> ==============================================================================
> --- python/branches/py3k/Modules/_pickle.c      (original)
> +++ python/branches/py3k/Modules/_pickle.c      Fri Jan 23 05:43:46 2009
> @@ -2881,7 +2881,7 @@
>  load_long(UnpicklerObject *self)
>  {
>     PyObject *value;
> -    char *s, *ss;
> +    char *s;
>     Py_ssize_t len;
>
>     if ((len = unpickler_readline(self, &s)) < 0)
> @@ -2894,17 +2894,9 @@
>        compatibility with Python 3.0.0, we don't actually *require*
>        the 'L' to be present. */
>     if (s[len-2] == 'L') {
> -        ss = (char *)PyMem_Malloc(len-1);
> -        if (ss == NULL) {
> -            PyErr_NoMemory();
> -            return -1;
> -        }
> -        strncpy(ss, s, len-2);
> -        ss[len-2] = '\0';
> -
> +        s[len-2] = '\0';
>         /* XXX: Should the base argument explicitly set to 10? */
> -        value = PyLong_FromString(ss, NULL, 0);
> -        PyMem_Free(ss);
> +        value = PyLong_FromString(s, NULL, 0);
>     }
>     else {
>         value = PyLong_FromString(s, NULL, 0);

Why not simplify further and bottom factor out the common line:
  value = PyLong_FromString(s, NULL, 0);

n


More information about the Python-checkins mailing list