[Python-checkins] python/nondist/sandbox/datetime datetime.py,1.83,1.84 obj_date.c,1.41,1.42 obj_datetime.c,1.40,1.41 obj_delta.c,1.25,1.26 obj_time.c,1.4,1.5
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
2002年12月08日 18:20:36 -0800
Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv5324
Modified Files:
datetime.py obj_date.c obj_datetime.c obj_delta.c obj_time.c
Log Message:
Reworked hashing to use __getstate__ instead of building tuples all the
time. This should be much faster for the C implementation, since
__getstate__ there just does a memcpy of the guts (for date, time, and
datetime objects).
Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.83
retrieving revision 1.84
diff -C2 -d -r1.83 -r1.84
*** datetime.py 8 Dec 2002 19:02:29 -0000 1.83
--- datetime.py 9 Dec 2002 02:20:34 -0000 1.84
***************
*** 462,466 ****
def __hash__(self):
! return hash((self.__days, self.__seconds, self.__microseconds))
def __nonzero__(self):
--- 462,466 ----
def __hash__(self):
! return hash(self.__getstate__())
def __nonzero__(self):
***************
*** 602,606 ****
def __hash__(self):
"Hash."
! return hash((self.__year, self.__month, self.__day))
# Formatting methods
--- 602,606 ----
def __hash__(self):
"Hash."
! return hash(self.__getstate__())
# Formatting methods
***************
*** 778,783 ****
def __hash__(self):
"""Hash."""
! return hash((self.__hour, self.__minute, self.__second,
! self.__microsecond))
# Conversions to string
--- 778,782 ----
def __hash__(self):
"""Hash."""
! return hash(self.__getstate__())
# Conversions to string
***************
*** 934,938 ****
"""Hash."""
tz = self.__tzinfo
! if tz == None:
return super(timetz, self).__hash__()
tzoff = tz.utcoffset(self)
--- 933,937 ----
"""Hash."""
tz = self.__tzinfo
! if tz is None:
return super(timetz, self).__hash__()
tzoff = tz.utcoffset(self)
***************
*** 942,947 ****
# Unfortunately it is not possible to construct a new timetz object
# and use super().__hash__(), since hour may exceed the range of
! # allowed values
! return hash((h, m, self.second, self.microsecond))
# Conversion to string
--- 941,949 ----
# Unfortunately it is not possible to construct a new timetz object
# and use super().__hash__(), since hour may exceed the range of
! # allowed values.
! if 0 <= h < 24:
! return hash(timetz(h, m, self.second, self.microsecond))
! else:
! return hash((h, m, self.second, self.microsecond))
# Conversion to string
***************
*** 1200,1206 ****
def __hash__(self):
"Hash."
! return hash((self.__year, self.__month, self.__day,
! self.__hour, self.__minute, self.__second,
! self.__microsecond))
# Formatting methods
--- 1202,1206 ----
def __hash__(self):
"Hash."
! return hash(self.__getstate__())
# Formatting methods
Index: obj_date.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_date.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -C2 -d -r1.41 -r1.42
*** obj_date.c 9 Dec 2002 01:51:11 -0000 1.41
--- obj_date.c 9 Dec 2002 02:20:34 -0000 1.42
***************
*** 378,389 ****
}
static long
date_hash(PyDateTime_Date *self)
{
if (self->hashcode == -1) {
! PyObject *temp = Py_BuildValue("iii",
! GET_YEAR(self),
! GET_MONTH(self),
! GET_DAY(self));
if (temp != NULL) {
self->hashcode = PyObject_Hash(temp);
--- 378,388 ----
}
+ static PyObject *date_getstate(PyDateTime_Date *self);
+
static long
date_hash(PyDateTime_Date *self)
{
if (self->hashcode == -1) {
! PyObject *temp = date_getstate(self);
if (temp != NULL) {
self->hashcode = PyObject_Hash(temp);
Index: obj_datetime.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_datetime.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** obj_datetime.c 9 Dec 2002 01:51:11 -0000 1.40
--- obj_datetime.c 9 Dec 2002 02:20:34 -0000 1.41
***************
*** 494,510 ****
}
static long
datetime_hash(PyDateTime_DateTime *self)
{
if (self->hashcode == -1) {
! PyObject *temp;
! temp = Py_BuildValue("iiiiiii",
! GET_YEAR(self),
! GET_MONTH(self),
! GET_DAY(self),
! DATE_GET_HOUR(self),
! DATE_GET_MINUTE(self),
! DATE_GET_SECOND(self),
! DATE_GET_MICROSECOND(self));
if (temp != NULL) {
self->hashcode = PyObject_Hash(temp);
--- 494,504 ----
}
+ static PyObject *datetime_getstate(PyDateTime_DateTime *self);
+
static long
datetime_hash(PyDateTime_DateTime *self)
{
if (self->hashcode == -1) {
! PyObject *temp = datetime_getstate(self);
if (temp != NULL) {
self->hashcode = PyObject_Hash(temp);
Index: obj_delta.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_delta.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** obj_delta.c 7 Dec 2002 22:29:45 -0000 1.25
--- obj_delta.c 9 Dec 2002 02:20:34 -0000 1.26
***************
*** 272,283 ****
}
static long
delta_hash(PyDateTime_Delta *self)
{
if (self->hashcode == -1) {
! PyObject *temp = Py_BuildValue("iii",
! (int)self->days,
! (int)self->seconds,
! (int)self->microseconds);
if (temp != NULL) {
self->hashcode = PyObject_Hash(temp);
--- 272,282 ----
}
+ static PyObject *delta_getstate(PyDateTime_Delta *self);
+
static long
delta_hash(PyDateTime_Delta *self)
{
if (self->hashcode == -1) {
! PyObject *temp = delta_getstate(self);
if (temp != NULL) {
self->hashcode = PyObject_Hash(temp);
Index: obj_time.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/obj_time.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** obj_time.c 7 Dec 2002 22:29:45 -0000 1.4
--- obj_time.c 9 Dec 2002 02:20:34 -0000 1.5
***************
*** 161,174 ****
}
static long
time_hash(PyDateTime_Time *self)
{
if (self->hashcode == -1) {
! PyObject *temp;
! temp = Py_BuildValue("iiii",
! TIME_GET_HOUR(self),
! TIME_GET_MINUTE(self),
! TIME_GET_SECOND(self),
! TIME_GET_MICROSECOND(self));
if (temp != NULL) {
self->hashcode = PyObject_Hash(temp);
--- 161,171 ----
}
+ static PyObject *time_getstate(PyDateTime_Time *self);
+
static long
time_hash(PyDateTime_Time *self)
{
if (self->hashcode == -1) {
! PyObject *temp = time_getstate(self);
if (temp != NULL) {
self->hashcode = PyObject_Hash(temp);