From 407c34df6184d67fb35350addfcc116a0f2fa9c1 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Sun, 5 Aug 2018 23:09:17 +0800 Subject: [PATCH] Revert "Merge pull request #999 from nanoric/optimize_ctp_performance" This reverts commit 8970554c2ca89f6008556454483d7e454a1458db, reversing changes made to 27e2159f4e53e7d16c05bdc9fce250ab5477804f. --- vnpy/api/ctp/vnctpmd/vnctpmd/vnctpmd.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/vnpy/api/ctp/vnctpmd/vnctpmd/vnctpmd.cpp b/vnpy/api/ctp/vnctpmd/vnctpmd/vnctpmd.cpp index 231a6520..df689fb2 100644 --- a/vnpy/api/ctp/vnctpmd/vnctpmd/vnctpmd.cpp +++ b/vnpy/api/ctp/vnctpmd/vnctpmd/vnctpmd.cpp @@ -7,7 +7,7 @@ ///从Python对象到C++类型转换用的函数 ///------------------------------------------------------------------------------------- -void getInt(dict d, const string &key, int *value) +void getInt(dict d, string key, int *value) { if (d.has_key(key)) //检查字典中是否存在该键值 { @@ -20,7 +20,7 @@ void getInt(dict d, const string &key, int *value) } }; -void getDouble(dict d, const string &key, double *value) +void getDouble(dict d, string key, double *value) { if (d.has_key(key)) { @@ -33,9 +33,7 @@ void getDouble(dict d, const string &key, double *value) } }; -// 使用特化的strcpy_s,能提升性能 -template -void getStr(dict d, const string &key, const CharType(&value)[size]) +void getStr(dict d, string key, char *value) { if (d.has_key(key)) { @@ -45,18 +43,18 @@ void getStr(dict d, const string &key, const CharType(&value)[size]) { string s = x(); const char *buffer = s.c_str(); + //对字符串指针赋值必须使用strcpy_s, vs2013使用strcpy编译通不过 + //+1应该是因为C++字符串的结尾符号?不是特别确定,不加这个1会出错 #ifdef _MSC_VER //WIN32 - strcpy_s(value, buffer); + strcpy_s(value, strlen(buffer) + 1, buffer); #elif __GNUC__ strncpy(value, buffer, strlen(buffer) + 1); -#else -#pragma error("unsupported compiler") #endif } } -} +}; -void getChar(dict d, const string &key, char *value) +void getChar(dict d, string key, char *value) { if (d.has_key(key)) {