From fbe7cd5638e7520349f06f3fddeb6bc18d0d324f Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Tue, 24 Apr 2018 11:05:43 -0400 Subject: constify and fix bug --- pyisda/curve.pxd | 6 +++--- pyisda/curve.pyx | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pyisda/curve.pxd b/pyisda/curve.pxd index 4e6dc51..76a0a4e 100644 --- a/pyisda/curve.pxd +++ b/pyisda/curve.pxd @@ -47,7 +47,7 @@ cdef inline size_t TCurve_size(int num_items) nogil: return sizeof(int) + sizeof(TDate) + sizeof(double) + \ sizeof(long) + sizeof(TRatePt) * num_items -cdef inline void serialize(TCurve* curve, unsigned char* buf) nogil: +cdef inline void serialize(const TCurve* curve, unsigned char* buf) nogil: memcpy(buf, &(curve.fNumItems), sizeof(curve.fNumItems)) buf += sizeof(curve.fNumItems) memcpy(buf, curve.fArray, sizeof(TRatePt) * curve.fNumItems) @@ -58,13 +58,13 @@ cdef inline void serialize(TCurve* curve, unsigned char* buf) nogil: buf += sizeof(double) memcpy(buf, &(curve.fDayCountConv), sizeof(long)) -cdef inline void serialize_vector(vector[TDate]& v, unsigned char* cursor) nogil: +cdef inline void serialize_vector(const vector[TDate]& v, unsigned char* cursor) nogil: cdef size_t size = v.size() memcpy(cursor, &size, sizeof(size_t)) cursor += sizeof(size_t) memcpy(cursor, v.data(), sizeof(TDate) * v.size()) -cdef inline unsigned char* serialize_string(string s, unsigned char* cursor) nogil: +cdef inline unsigned char* serialize_string(const string& s, unsigned char* cursor) nogil: cdef size_t size = s.length() memcpy(cursor, &size, sizeof(size_t)) cursor += sizeof(size_t) diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx index 545c7ee..7e5ee58 100644 --- a/pyisda/curve.pyx +++ b/pyisda/curve.pyx @@ -632,6 +632,7 @@ cdef class SpreadCurve(Curve): return instance def __hash__(self): + # same code as __getstate__ cdef: TCurve* curve = self._thisptr.get() size_t size = TCurve_size(curve.fNumItems) @@ -640,7 +641,7 @@ cdef class SpreadCurve(Curve): unsigned char* buf = malloc(buf_size) unsigned char* cursor = buf + size serialize(curve, buf) - cursor += self.ticker.copy(cursor, self.ticker.length(), 0) + cursor = serialize_string(self.ticker, cursor) memcpy(cursor, self.recovery_rates.get(), curve.fNumItems * sizeof(double)) cdef uint64_t r = Hash64(buf, buf_size) free(buf) -- cgit v1.2.3-70-g09d2