优化 Stock 相等比较

This commit is contained in:
fasiondog 2023-10-28 17:42:43 +08:00
parent 2bbb700eb6
commit 2c23644593
2 changed files with 14 additions and 16 deletions

View File

@ -158,12 +158,10 @@ Stock::Stock(const string& market, const string& code, const string& name, uint3
: m_data(make_shared<Data>(market, code, name, type, valid, startDate, lastDate, tick, tickValue,
precision, minTradeNumber, maxTradeNumber)) {}
bool Stock::operator!=(const Stock& stock) const {
HKU_IF_RETURN(this == &stock, false);
HKU_IF_RETURN(m_data == stock.m_data, false);
HKU_IF_RETURN(!m_data || !stock.m_data, true);
HKU_IF_RETURN(m_data->m_code != stock.code() || m_data->m_market != stock.market(), true);
return false;
bool Stock::operator==(const Stock& stock) const {
return this == &stock || m_data == stock.m_data ||
(m_data && stock.m_data && (m_data->m_code == stock.m_data->m_code) &&
(m_data->m_market == stock.m_data->m_market));
}
const string& Stock::market() const {

View File

@ -233,14 +233,14 @@ private:
};
struct HKU_API Stock::Data {
string m_market; // 所属的市场简称
string m_code; // 证券代码
string m_market_code; // 市场简称证券代码
string m_name; // 证券名称
uint32_t m_type; // 证券类型
bool m_valid; // 当前证券是否有效
Datetime m_startDate; // 证券起始日期
Datetime m_lastDate; // 证券最后日期
string m_market; // 所属的市场简称
string m_code; // 证券代码
string m_market_code; // 市场简称证券代码
string m_name; // 证券名称
uint32_t m_type; // 证券类型
bool m_valid; // 当前证券是否有效
Datetime m_startDate; // 证券起始日期
Datetime m_lastDate; // 证券最后日期
StockWeightList m_weightList; // 权息信息列表
std::mutex m_weight_mutex;
@ -291,8 +291,8 @@ inline uint64_t Stock::id() const {
return isNull() ? 0 : (int64_t)m_data.get();
}
inline bool Stock::operator==(const Stock& stock) const {
return (*this != stock) ? false : true;
inline bool Stock::operator!=(const Stock& stock) const {
return !(*this == stock);
}
} // namespace hku