summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2018-04-24 11:05:43 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2018-04-24 11:05:43 -0400
commitfbe7cd5638e7520349f06f3fddeb6bc18d0d324f (patch)
tree5d523cc849c00fd80bd5578cd46cfc70dd8ebd1d
parentaafbb899735c3d90a95e37c5e78fca8307d73c8b (diff)
downloadpyisda-fbe7cd5638e7520349f06f3fddeb6bc18d0d324f.tar.gz
constify and fix bug
-rw-r--r--pyisda/curve.pxd6
-rw-r--r--pyisda/curve.pyx3
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 = <unsigned char*>malloc(buf_size)
unsigned char* cursor = buf + size
serialize(curve, buf)
- cursor += self.ticker.copy(<char*>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(<char*>buf, buf_size)
free(buf)