[Python-checkins] CVS: python/dist/src/Objects dictobject.c,2.94,2.95 stringobject.c,2.116,2.117
Martin v. L?wis
loewis@users.sourceforge.net
Thu, 24 May 2001 09:56:37 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv11296/Objects
Modified Files:
dictobject.c stringobject.c
Log Message:
Patch #424335: Implement string_richcompare, remove string_compare.
Use new _PyString_Eq in lookdict_string.
Index: dictobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/dictobject.c,v
retrieving revision 2.94
retrieving revision 2.95
diff -C2 -r2.94 -r2.95
*** dictobject.c 2001/05/24 16:26:40 2.94
--- dictobject.c 2001/05/24 16:56:35 2.95
***************
*** 295,299 ****
* be dropped; string-string comparisons never raise exceptions. This also
* means we don't need to go through PyObject_Compare(); we can always use
! * the tp_compare slot of the string type object directly.
*
* This really only becomes meaningful if proper error handling in lookdict()
--- 295,299 ----
* be dropped; string-string comparisons never raise exceptions. This also
* means we don't need to go through PyObject_Compare(); we can always use
! * _PyString_Eq directly.
*
* This really only becomes meaningful if proper error handling in lookdict()
***************
*** 309,313 ****
dictentry *ep0 = mp->ma_table;
register dictentry *ep;
- cmpfunc compare = PyString_Type.tp_compare;
/* make sure this function doesn't have to handle non-string keys */
--- 309,312 ----
***************
*** 329,333 ****
else {
if (ep->me_hash == hash
! && compare(ep->me_key, key) == 0) {
return ep;
}
--- 328,332 ----
else {
if (ep->me_hash == hash
! && _PyString_Eq(ep->me_key, key)) {
return ep;
}
***************
*** 348,352 ****
|| (ep->me_hash == hash
&& ep->me_key != dummy
! && compare(ep->me_key, key) == 0))
return ep;
if (ep->me_key == dummy && freeslot == NULL)
--- 347,351 ----
|| (ep->me_hash == hash
&& ep->me_key != dummy
! && _PyString_Eq(ep->me_key, key)))
return ep;
if (ep->me_key == dummy && freeslot == NULL)
Index: stringobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.116
retrieving revision 2.117
diff -C2 -r2.116 -r2.117
*** stringobject.c 2001/05/15 11:58:06 2.116
--- stringobject.c 2001/05/24 16:56:35 2.117
***************
*** 631,648 ****
}
! static int
! string_compare(PyStringObject *a, PyStringObject *b)
{
! int len_a = a->ob_size, len_b = b->ob_size;
! int min_len = (len_a < len_b) ? len_a : len_b;
! int cmp;
! if (min_len > 0) {
! cmp = Py_CHARMASK(*a->ob_sval) - Py_CHARMASK(*b->ob_sval);
! if (cmp == 0)
! cmp = memcmp(a->ob_sval, b->ob_sval, min_len);
! if (cmp != 0)
! return cmp;
}
! return (len_a < len_b) ? -1 : (len_a > len_b) ? 1 : 0;
}
--- 631,707 ----
}
! static PyObject*
! string_richcompare(PyStringObject *a, PyStringObject *b, int op)
{
! int c;
! int len_a, len_b;
! int min_len;
! PyObject *result;
!
! /* One of the objects is a string object. Make sure the
! other one is one, too. */
! if (a->ob_type != b->ob_type) {
! result = Py_NotImplemented;
! goto out;
! }
! if (a == b) {
! switch (op) {
! case Py_EQ:case Py_LE:case Py_GE:
! result = Py_True;
! goto out;
! case Py_NE:case Py_LT:case Py_GT:
! result = Py_False;
! goto out;
! }
! }
! if (op == Py_EQ) {
! /* Supporting Py_NE here as well does not save
! much time, since Py_NE is rarely used. */
! if (a->ob_size == b->ob_size
! && (a->ob_sval[0] == b->ob_sval[0]
! && memcmp(a->ob_sval, b->ob_sval,
! a->ob_size) == 0)) {
! result = Py_True;
! } else {
! result = Py_False;
! }
! goto out;
}
! len_a = a->ob_size; len_b = b->ob_size;
! min_len = (len_a < len_b) ? len_a : len_b;
! if (min_len > 0) {
! c = Py_CHARMASK(*a->ob_sval) - Py_CHARMASK(*b->ob_sval);
! if (c==0)
! c = memcmp(a->ob_sval, b->ob_sval, min_len);
! }else
! c = 0;
! if (c == 0)
! c = (len_a < len_b) ? -1 : (len_a > len_b) ? 1 : 0;
! switch (op) {
! case Py_LT: c = c < 0; break;
! case Py_LE: c = c <= 0; break;
! case Py_EQ: assert(0); break; /* unreachable */
! case Py_NE: c = c != 0; break;
! case Py_GT: c = c > 0; break;
! case Py_GE: c = c >= 0; break;
! default:
! result = Py_NotImplemented;
! goto out;
! }
! result = c ? Py_True : Py_False;
! out:
! Py_INCREF(result);
! return result;
! }
!
! int
! _PyString_Eq(PyObject *o1, PyObject *o2)
! {
! PyStringObject *a, *b;
! a = (PyStringObject*)o1;
! b = (PyStringObject*)o2;
! return a->ob_size == b->ob_size
! && *a->ob_sval == *b->ob_sval
! && memcmp(a->ob_sval, b->ob_sval, a->ob_size) == 0;
}
***************
*** 2467,2471 ****
(getattrfunc)string_getattr, /*tp_getattr*/
0, /*tp_setattr*/
! (cmpfunc)string_compare, /*tp_compare*/
(reprfunc)string_repr, /*tp_repr*/
0, /*tp_as_number*/
--- 2526,2530 ----
(getattrfunc)string_getattr, /*tp_getattr*/
0, /*tp_setattr*/
! 0, /*tp_compare*/
(reprfunc)string_repr, /*tp_repr*/
0, /*tp_as_number*/
***************
*** 2480,2483 ****
--- 2539,2548 ----
Py_TPFLAGS_DEFAULT, /*tp_flags*/
0, /*tp_doc*/
+ 0, /*tp_traverse*/
+ 0, /*tp_clear*/
+ (richcmpfunc)string_richcompare, /*tp_richcompare*/
+ 0, /*tp_weaklistoffset*/
+ 0, /*tp_iter*/
+ 0, /*tp_iternext*/
};