Karsten Hopp f074fb
To: vim_dev@googlegroups.com
Karsten Hopp f074fb
Subject: Patch 7.3.1161
Karsten Hopp f074fb
Fcc: outbox
Karsten Hopp f074fb
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp f074fb
Mime-Version: 1.0
Karsten Hopp f074fb
Content-Type: text/plain; charset=UTF-8
Karsten Hopp f074fb
Content-Transfer-Encoding: 8bit
Karsten Hopp f074fb
------------
Karsten Hopp f074fb
Karsten Hopp f074fb
Patch 7.3.1161
Karsten Hopp f074fb
Problem:    Python: PyList_SetItem() is inefficient.
Karsten Hopp f074fb
Solution:   Use PyList_SET_ITEM() (ZyX)
Karsten Hopp f074fb
Files:	    src/if_py_both.h
Karsten Hopp f074fb
Karsten Hopp f074fb
Karsten Hopp f074fb
*** ../vim-7.3.1160/src/if_py_both.h	2013-06-05 20:34:07.000000000 +0200
Karsten Hopp f074fb
--- src/if_py_both.h	2013-06-10 20:37:50.000000000 +0200
Karsten Hopp f074fb
***************
Karsten Hopp f074fb
*** 375,382 ****
Karsten Hopp f074fb
      static int
Karsten Hopp f074fb
  PythonIO_Init_io(void)
Karsten Hopp f074fb
  {
Karsten Hopp f074fb
!     PySys_SetObject("stdout", (PyObject *)(void *)&Output);
Karsten Hopp f074fb
!     PySys_SetObject("stderr", (PyObject *)(void *)&Error);
Karsten Hopp f074fb
  
Karsten Hopp f074fb
      if (PyErr_Occurred())
Karsten Hopp f074fb
      {
Karsten Hopp f074fb
--- 375,384 ----
Karsten Hopp f074fb
      static int
Karsten Hopp f074fb
  PythonIO_Init_io(void)
Karsten Hopp f074fb
  {
Karsten Hopp f074fb
!     if (PySys_SetObject("stdout", (PyObject *)(void *)&Output))
Karsten Hopp f074fb
! 	return -1;
Karsten Hopp f074fb
!     if (PySys_SetObject("stderr", (PyObject *)(void *)&Error))
Karsten Hopp f074fb
! 	return -1;
Karsten Hopp f074fb
  
Karsten Hopp f074fb
      if (PyErr_Occurred())
Karsten Hopp f074fb
      {
Karsten Hopp f074fb
***************
Karsten Hopp f074fb
*** 1319,1330 ****
Karsten Hopp f074fb
  		Py_DECREF(r);
Karsten Hopp f074fb
  		return NULL;
Karsten Hopp f074fb
  	    }
Karsten Hopp f074fb
! 	    if (PyList_SetItem(r, i, newObj))
Karsten Hopp f074fb
! 	    {
Karsten Hopp f074fb
! 		Py_DECREF(r);
Karsten Hopp f074fb
! 		Py_DECREF(newObj);
Karsten Hopp f074fb
! 		return NULL;
Karsten Hopp f074fb
! 	    }
Karsten Hopp f074fb
  	    --todo;
Karsten Hopp f074fb
  	    ++i;
Karsten Hopp f074fb
  	}
Karsten Hopp f074fb
--- 1321,1327 ----
Karsten Hopp f074fb
  		Py_DECREF(r);
Karsten Hopp f074fb
  		return NULL;
Karsten Hopp f074fb
  	    }
Karsten Hopp f074fb
! 	    PyList_SET_ITEM(r, i, newObj);
Karsten Hopp f074fb
  	    --todo;
Karsten Hopp f074fb
  	    ++i;
Karsten Hopp f074fb
  	}
Karsten Hopp f074fb
***************
Karsten Hopp f074fb
*** 1808,1819 ****
Karsten Hopp f074fb
  	    return NULL;
Karsten Hopp f074fb
  	}
Karsten Hopp f074fb
  
Karsten Hopp f074fb
! 	if ((PyList_SetItem(list, ((reversed)?(n-i-1):(i)), item)))
Karsten Hopp f074fb
! 	{
Karsten Hopp f074fb
! 	    Py_DECREF(item);
Karsten Hopp f074fb
! 	    Py_DECREF(list);
Karsten Hopp f074fb
! 	    return NULL;
Karsten Hopp f074fb
! 	}
Karsten Hopp f074fb
      }
Karsten Hopp f074fb
  
Karsten Hopp f074fb
      return list;
Karsten Hopp f074fb
--- 1805,1811 ----
Karsten Hopp f074fb
  	    return NULL;
Karsten Hopp f074fb
  	}
Karsten Hopp f074fb
  
Karsten Hopp f074fb
! 	PyList_SET_ITEM(list, ((reversed)?(n-i-1):(i)), item);
Karsten Hopp f074fb
      }
Karsten Hopp f074fb
  
Karsten Hopp f074fb
      return list;
Karsten Hopp f074fb
***************
Karsten Hopp f074fb
*** 3164,3176 ****
Karsten Hopp f074fb
  	    return NULL;
Karsten Hopp f074fb
  	}
Karsten Hopp f074fb
  
Karsten Hopp f074fb
! 	/* Set the list item */
Karsten Hopp f074fb
! 	if (PyList_SetItem(list, i, str))
Karsten Hopp f074fb
! 	{
Karsten Hopp f074fb
! 	    Py_DECREF(str);
Karsten Hopp f074fb
! 	    Py_DECREF(list);
Karsten Hopp f074fb
! 	    return NULL;
Karsten Hopp f074fb
! 	}
Karsten Hopp f074fb
      }
Karsten Hopp f074fb
  
Karsten Hopp f074fb
      /* The ownership of the Python list is passed to the caller (ie,
Karsten Hopp f074fb
--- 3156,3162 ----
Karsten Hopp f074fb
  	    return NULL;
Karsten Hopp f074fb
  	}
Karsten Hopp f074fb
  
Karsten Hopp f074fb
! 	PyList_SET_ITEM(list, i, str);
Karsten Hopp f074fb
      }
Karsten Hopp f074fb
  
Karsten Hopp f074fb
      /* The ownership of the Python list is passed to the caller (ie,
Karsten Hopp f074fb
***************
Karsten Hopp f074fb
*** 5366,5373 ****
Karsten Hopp f074fb
      static int
Karsten Hopp f074fb
  populate_module(PyObject *m, object_adder add_object, attr_getter get_attr)
Karsten Hopp f074fb
  {
Karsten Hopp f074fb
!     int i;
Karsten Hopp f074fb
!     PyObject	*os;
Karsten Hopp f074fb
  
Karsten Hopp f074fb
      for (i = 0; i < (int)(sizeof(numeric_constants)
Karsten Hopp f074fb
  					   / sizeof(struct numeric_constant));
Karsten Hopp f074fb
--- 5352,5359 ----
Karsten Hopp f074fb
      static int
Karsten Hopp f074fb
  populate_module(PyObject *m, object_adder add_object, attr_getter get_attr)
Karsten Hopp f074fb
  {
Karsten Hopp f074fb
!     int		i;
Karsten Hopp f074fb
!     PyObject	*other_module;
Karsten Hopp f074fb
  
Karsten Hopp f074fb
      for (i = 0; i < (int)(sizeof(numeric_constants)
Karsten Hopp f074fb
  					   / sizeof(struct numeric_constant));
Karsten Hopp f074fb
***************
Karsten Hopp f074fb
*** 5395,5418 ****
Karsten Hopp f074fb
      ADD_CHECKED_OBJECT(m, "options",
Karsten Hopp f074fb
  	    OptionsNew(SREQ_GLOBAL, NULL, dummy_check, NULL));
Karsten Hopp f074fb
  
Karsten Hopp f074fb
!     if (!(os = PyImport_ImportModule("os")))
Karsten Hopp f074fb
  	return -1;
Karsten Hopp f074fb
!     ADD_OBJECT(m, "os", os);
Karsten Hopp f074fb
  
Karsten Hopp f074fb
!     if (!(py_getcwd = PyObject_GetAttrString(os, "getcwd")))
Karsten Hopp f074fb
  	return -1;
Karsten Hopp f074fb
      ADD_OBJECT(m, "_getcwd", py_getcwd)
Karsten Hopp f074fb
  
Karsten Hopp f074fb
!     if (!(py_chdir = PyObject_GetAttrString(os, "chdir")))
Karsten Hopp f074fb
  	return -1;
Karsten Hopp f074fb
      ADD_OBJECT(m, "_chdir", py_chdir);
Karsten Hopp f074fb
!     if (PyObject_SetAttrString(os, "chdir", get_attr(m, "chdir")))
Karsten Hopp f074fb
  	return -1;
Karsten Hopp f074fb
  
Karsten Hopp f074fb
!     if ((py_fchdir = PyObject_GetAttrString(os, "fchdir")))
Karsten Hopp f074fb
      {
Karsten Hopp f074fb
  	ADD_OBJECT(m, "_fchdir", py_fchdir);
Karsten Hopp f074fb
! 	if (PyObject_SetAttrString(os, "fchdir", get_attr(m, "fchdir")))
Karsten Hopp f074fb
  	    return -1;
Karsten Hopp f074fb
      }
Karsten Hopp f074fb
      else
Karsten Hopp f074fb
--- 5381,5404 ----
Karsten Hopp f074fb
      ADD_CHECKED_OBJECT(m, "options",
Karsten Hopp f074fb
  	    OptionsNew(SREQ_GLOBAL, NULL, dummy_check, NULL));
Karsten Hopp f074fb
  
Karsten Hopp f074fb
!     if (!(other_module = PyImport_ImportModule("os")))
Karsten Hopp f074fb
  	return -1;
Karsten Hopp f074fb
!     ADD_OBJECT(m, "os", other_module);
Karsten Hopp f074fb
  
Karsten Hopp f074fb
!     if (!(py_getcwd = PyObject_GetAttrString(other_module, "getcwd")))
Karsten Hopp f074fb
  	return -1;
Karsten Hopp f074fb
      ADD_OBJECT(m, "_getcwd", py_getcwd)
Karsten Hopp f074fb
  
Karsten Hopp f074fb
!     if (!(py_chdir = PyObject_GetAttrString(other_module, "chdir")))
Karsten Hopp f074fb
  	return -1;
Karsten Hopp f074fb
      ADD_OBJECT(m, "_chdir", py_chdir);
Karsten Hopp f074fb
!     if (PyObject_SetAttrString(other_module, "chdir", get_attr(m, "chdir")))
Karsten Hopp f074fb
  	return -1;
Karsten Hopp f074fb
  
Karsten Hopp f074fb
!     if ((py_fchdir = PyObject_GetAttrString(other_module, "fchdir")))
Karsten Hopp f074fb
      {
Karsten Hopp f074fb
  	ADD_OBJECT(m, "_fchdir", py_fchdir);
Karsten Hopp f074fb
! 	if (PyObject_SetAttrString(other_module,"fchdir",get_attr(m,"fchdir")))
Karsten Hopp f074fb
  	    return -1;
Karsten Hopp f074fb
      }
Karsten Hopp f074fb
      else
Karsten Hopp f074fb
*** ../vim-7.3.1160/src/version.c	2013-06-10 20:25:05.000000000 +0200
Karsten Hopp f074fb
--- src/version.c	2013-06-10 20:37:02.000000000 +0200
Karsten Hopp f074fb
***************
Karsten Hopp f074fb
*** 730,731 ****
Karsten Hopp f074fb
--- 730,733 ----
Karsten Hopp f074fb
  {   /* Add new patch number below this line */
Karsten Hopp f074fb
+ /**/
Karsten Hopp f074fb
+     1161,
Karsten Hopp f074fb
  /**/
Karsten Hopp f074fb
Karsten Hopp f074fb
-- 
Karsten Hopp f074fb
hundred-and-one symptoms of being an internet addict:
Karsten Hopp f074fb
136. You decide to stay in a low-paying job teaching just for the
Karsten Hopp f074fb
     free Internet access.
Karsten Hopp f074fb
Karsten Hopp f074fb
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp f074fb
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp f074fb
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp f074fb
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///