[Python-checkins] python/dist/src/Objects object.c,2.206.2.2,2.206.2.3

ping@users.sourceforge.net ping@users.sourceforge.net
Tue, 25 Mar 2003 18:16:29 -0800


Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv5139

Modified Files:
      Tag: cache-attr-branch
	object.c 
Log Message:
Minor adjustments.  Seems to be a touch faster for method lookup.


Index: object.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/object.c,v
retrieving revision 2.206.2.2
retrieving revision 2.206.2.3
diff -C2 -d -r2.206.2.2 -r2.206.2.3
*** object.c	25 Mar 2003 23:04:43 -0000	2.206.2.2
--- object.c	26 Mar 2003 02:16:26 -0000	2.206.2.3
***************
*** 1358,1389 ****
  
  /* Find the dict where an attribute resides, and return it un-INCREFed.  */
! /* In addition, cache/return whether the value is a descriptor-with-set; and */
! /* cache/return the value itself if the value is a descriptor-with-get. */
  PyObject *_PyObject_FindAttr(PyTypeObject *tp, PyObject *name,
  			     PyObject **descr, int *isdata)
  {
! 	PyObject *triple = NULL;
! 	PyObject *value;
! 	PyObject *cache_where = Py_None;
! 	PyObject *cache_descr = Py_None;
! 	PyObject *cache_isdata = Py_False;
  
  	if (tp->tp_cache != NULL) {
  		triple = PyDict_GetItem(tp->tp_cache, name);
- 		/* pair is not owned by this func */
  		if (triple) {
! 			cache_where = PyTuple_GET_ITEM(triple, 0);
! 			cache_descr = PyTuple_GET_ITEM(triple, 1);
! 			cache_isdata = PyTuple_GET_ITEM(triple, 2);
! 			goto done;
  		}
  	}
  	
! 	/* Inline _PyType_Lookup */
  	{
  		int i, n;
  		PyObject *mro, *base, *dict;
  
! 		/* Look in tp_dict of types in MRO */
  		mro = tp->tp_mro;
  		assert(mro != NULL);
--- 1358,1390 ----
  
  /* Find the dict where an attribute resides, and return it un-INCREFed.  */
! /* In addition, cache/return whether the value is a descr-with-set; and  */
! /* cache/return the value itself if the value is a descr-with-get.       */
! static inline
  PyObject *_PyObject_FindAttr(PyTypeObject *tp, PyObject *name,
  			     PyObject **descr, int *isdata)
  {
! 	PyObject *triple, *value;
! 	PyObject *cache_where, *cache_descr, *cache_isdata;
  
  	if (tp->tp_cache != NULL) {
+ 		/* Fetch entry from the cache. */
  		triple = PyDict_GetItem(tp->tp_cache, name);
  		if (triple) {
! 			*descr = PyTuple_GET_ITEM(triple, 1);
! 			*isdata = (PyTuple_GET_ITEM(triple, 2) == Py_True);
! 			return PyTuple_GET_ITEM(triple, 0);
  		}
  	}
+ 
+ 	cache_where = Py_None;
+ 	cache_descr = Py_None;
+ 	cache_isdata = Py_False;
  	
! 	/* Just like _PyType_Lookup, but keep information for the cache. */
  	{
  		int i, n;
  		PyObject *mro, *base, *dict;
  
! 		/* Look in tp_dict of types in MRO. */
  		mro = tp->tp_mro;
  		assert(mro != NULL);
***************
*** 1412,1415 ****
--- 1413,1417 ----
  
  	if (tp->tp_cache != NULL) {
+ 		/* Add entry to the cache. */
  		triple = PyTuple_New(3);
  		Py_INCREF(cache_where);
***************
*** 1423,1436 ****
  	}
  
!   done:
! 	if (cache_descr == Py_None)
! 		*descr = NULL;
! 	else
! 		*descr = cache_descr;
  	*isdata = (cache_isdata == Py_True);
! 	if (cache_where == Py_None)
! 		return NULL;
! 	else
! 		return cache_where;
  }
  
--- 1425,1431 ----
  	}
  
! 	*descr = cache_descr;
  	*isdata = (cache_isdata == Py_True);
! 	return cache_where;
  }
  
***************
*** 1440,1445 ****
  	PyTypeObject *tp = obj->ob_type;
  	PyObject *where;
! 	PyObject *descr = NULL;
! 	int isdata = 0;
  	PyObject *res = NULL;
  	descrgetfunc descr_get;
--- 1435,1440 ----
  	PyTypeObject *tp = obj->ob_type;
  	PyObject *where;
! 	PyObject *descr;
! 	int isdata;
  	PyObject *res = NULL;
  	descrgetfunc descr_get;
***************
*** 1508,1512 ****
  	}
  
! 	if (descr != NULL) {
  		descr_get = GET_DESCR_FIELD(descr, tp_descr_get);
  		assert(descr_get != NULL);
--- 1503,1507 ----
  	}
  
! 	if (descr != Py_None) {
  		descr_get = GET_DESCR_FIELD(descr, tp_descr_get);
  		assert(descr_get != NULL);
***************
*** 1515,1519 ****
  	}
  
! 	if (where != NULL) {
  		res = PyDict_GetItem(where, name);
  		assert(res != NULL);
--- 1510,1514 ----
  	}
  
! 	if (where != Py_None) {
  		res = PyDict_GetItem(where, name);
  		assert(res != NULL);
***************
*** 1599,1603 ****
  	}
  
! 	if (descr == NULL) {
  		PyErr_Format(PyExc_AttributeError,
  			     "'%.50s' object has no attribute '%.400s'",
--- 1594,1598 ----
  	}
  
! 	if (descr == Py_None) {
  		PyErr_Format(PyExc_AttributeError,
  			     "'%.50s' object has no attribute '%.400s'",