Skip to content

Commit 64dc174

Browse files
authored
Merge pull request #446 from fasiondog/feature/dev
perf(indicator): 优化参数获取性能
2 parents bff5a6a + 42e24f0 commit 64dc174

File tree

6 files changed

+8
-8
lines changed

6 files changed

+8
-8
lines changed

hikyuu_cpp/hikyuu/indicator/IndicatorImp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ DatetimeList IndicatorImp::getDatetimeList() const {
533533

534534
Datetime IndicatorImp::getDatetime(size_t pos) const {
535535
if (haveParam("align_date_list")) {
536-
DatetimeList dates(getParam<DatetimeList>("align_date_list"));
536+
const DatetimeList &dates = getParam<const DatetimeList &>("align_date_list");
537537
return pos < dates.size() ? dates[pos] : Null<Datetime>();
538538
}
539539
const KData &k = getContext();
@@ -547,7 +547,7 @@ IndicatorImp::value_t IndicatorImp::getByDate(Datetime date, size_t num) {
547547

548548
size_t IndicatorImp::getPos(Datetime date) const {
549549
if (haveParam("align_date_list")) {
550-
DatetimeList dates(getParam<DatetimeList>("align_date_list"));
550+
const DatetimeList &dates(getParam<const DatetimeList &>("align_date_list"));
551551
auto iter = std::lower_bound(dates.begin(), dates.end(), date);
552552
if (iter != dates.end() && *iter == date) {
553553
return iter - dates.begin();

hikyuu_cpp/hikyuu/indicator/imp/IBlockSetNum.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ void IBlockSetNum::_checkParam(const string& name) const {
3535
}
3636

3737
void IBlockSetNum::_calculate(const Indicator& ind) {
38-
Block block = getParam<Block>("block");
38+
const Block block = getParam<const Block&>("block");
3939
bool ignore_context = getParam<bool>("ignore_context");
4040
const KData& k = getContext();
4141
DatetimeList dates;
4242
if (!ignore_context && !k.empty()) {
4343
dates = k.getDatetimeList();
4444
} else {
45-
KQuery q = getParam<KQuery>("query");
45+
const KQuery& q = getParam<const KQuery&>("query");
4646
if (q != KQuery(0, 0)) {
4747
dates = StockManager::instance().getTradingCalendar(q, getParam<string>("market"));
4848
}

hikyuu_cpp/hikyuu/indicator/imp/IInSum.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ static void insum_rank_asc(const IndicatorList& inds, Indicator::value_t* dst, c
225225
}
226226

227227
void IInSum::_calculate(const Indicator& ind) {
228-
Block block = getParam<Block>("block");
228+
const Block block = getParam<const Block&>("block");
229229
bool ignore_context = getParam<bool>("ignore_context");
230230
const KData& k = getContext();
231231
KQuery q;

hikyuu_cpp/hikyuu/indicator/imp/IPriceList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void IPriceList::_calculate(const Indicator& data) {
4343

4444
DatetimeList align_dates =
4545
haveParam("align_date_list") ? getParam<DatetimeList>("align_date_list") : DatetimeList();
46-
PriceList x = getParam<PriceList>("data");
46+
const PriceList& x = getParam<const PriceList&>("data");
4747
int x_discard = getParam<int>("discard");
4848
size_t x_total = x.size();
4949

hikyuu_cpp/hikyuu/indicator/imp/ISlice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void ISlice::_calculate(const Indicator& data) {
3939
// 如果在叶子节点,直接取自身的data参数
4040
if (isLeaf()) {
4141
m_discard = 0;
42-
PriceList x = getParam<PriceList>("data");
42+
const PriceList& x = getParam<const PriceList&>("data");
4343
size_t total = x.size();
4444
int64_t startix = getParam<int64_t>("start");
4545
if (startix < 0) {

hikyuu_cpp/hikyuu/trade_sys/allocatefunds/imp/FixedWeightListAllocateFunds.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void FixedWeightListAllocateFunds::_checkParam(const string& name) const {
3939
SystemWeightList FixedWeightListAllocateFunds ::_allocateWeight(const Datetime& date,
4040
const SystemWeightList& se_list) {
4141
SystemWeightList result;
42-
PriceList weights = getParam<PriceList>("weights");
42+
const PriceList& weights = getParam<const PriceList&>("weights");
4343
size_t w_total = weights.size();
4444
size_t wi = 0;
4545
for (auto iter = se_list.begin(); iter != se_list.end() && wi < w_total; ++iter) {

0 commit comments

Comments
 (0)