From 332da554c67ede42217f4bb6fdf29192a57fca46 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Wed, 7 Jun 2017 15:01:17 -0400 Subject: small cleanup --- pyisda/curve.pxd | 18 +++++++++--------- pyisda/curve.pyx | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pyisda/curve.pxd b/pyisda/curve.pxd index 2419d1d..f736f30 100644 --- a/pyisda/curve.pxd +++ b/pyisda/curve.pxd @@ -6,6 +6,10 @@ from libcpp.string cimport string from libc.string cimport memcpy from libc.stdlib cimport malloc, calloc, free from libc.stdint cimport uint64_t + +cdef extern from "string.h" nogil: + void* mempcpy(void* dest, const void* src, size_t n) + cdef extern from "isda/zerocurve.h" nogil: ctypedef int TBoolean @@ -46,17 +50,13 @@ cdef inline size_t TCurve_size(int num_items) nogil: sizeof(long) + sizeof(TRatePt) * num_items cdef inline void serialize(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) - buf += sizeof(TRatePt) * curve.fNumItems - memcpy(buf, &(curve.fBaseDate), sizeof(TDate)) - buf += sizeof(TDate) - memcpy(buf, &(curve.fBasis), sizeof(double)) - buf += sizeof(double) + buf = mempcpy(buf, &(curve.fNumItems), sizeof(curve.fNumItems)) + buf = mempcpy(buf, curve.fArray, sizeof(TRatePt) * curve.fNumItems) + buf = memcpy(buf, &(curve.fBaseDate), sizeof(TDate)) + buf = mempcpy(buf, &(curve.fBasis), sizeof(double)) memcpy(buf, &(curve.fDayCountConv), sizeof(long)) -cdef inline unsigned char* unserialize(unsigned char* buf, TCurve* curve) nogil: +cdef inline unsigned char* deserialize(unsigned char* buf, TCurve* curve) nogil: memcpy(&curve.fNumItems, buf, sizeof(curve.fNumItems)) buf += sizeof(curve.fNumItems) cdef size_t array_size = sizeof(TRatePt) * curve.fNumItems diff --git a/pyisda/curve.pyx b/pyisda/curve.pyx index 99d880a..0650af1 100644 --- a/pyisda/curve.pyx +++ b/pyisda/curve.pyx @@ -44,7 +44,7 @@ cdef class Curve(object): cdef: TCurve* curve = malloc(sizeof(TCurve)) unsigned char* cursor = state - unserialize(cursor, curve) + deserialize(cursor, curve) self._thisptr = make_shared(curve) @classmethod @@ -53,7 +53,7 @@ cdef class Curve(object): Curve instance = Curve.__new__(Curve) unsigned char* cursor = state TCurve* curve = malloc(sizeof(TCurve)) - unserialize(cursor, curve) + deserialize(cursor, curve) instance._thisptr = make_shared(curve) return instance @@ -293,7 +293,7 @@ cdef class YieldCurve(Curve): unsigned char* cursor = state size_t num_instr - cursor = unserialize(cursor, curve) + cursor = deserialize(cursor, curve) self._thisptr = make_shared(curve) memcpy(&num_instr, cursor, sizeof(size_t)) cursor += sizeof(size_t) @@ -308,7 +308,7 @@ cdef class YieldCurve(Curve): TCurve* curve = malloc(sizeof(TCurve)) size_t num_instr - cursor = unserialize(cursor, curve) + cursor = deserialize(cursor, curve) instance._thisptr = make_shared(curve) memcpy(&num_instr, cursor, sizeof(size_t)) cursor += sizeof(size_t) @@ -512,7 +512,7 @@ cdef class SpreadCurve(Curve): unsigned char* cursor = state size_t ticker_length - cursor = unserialize(cursor, curve) + cursor = deserialize(cursor, curve) self._thisptr = make_shared(curve) memcpy(&ticker_length, cursor, sizeof(size_t)) cursor += sizeof(size_t) @@ -526,7 +526,7 @@ cdef class SpreadCurve(Curve): TCurve* curve = malloc(sizeof(TCurve)) size_t ticker_length - cursor = unserialize(cursor, curve) + cursor = deserialize(cursor, curve) instance._thisptr = make_shared(curve) memcpy(&ticker_length, cursor, sizeof(size_t)) cursor += sizeof(size_t) -- cgit v1.2.3-70-g09d2