减少选股状态热路径字符串分配
This commit is contained in:
@@ -986,6 +986,7 @@ pub struct PlatformExprStrategy {
|
|||||||
prelude_identifier_candidates: BTreeSet<String>,
|
prelude_identifier_candidates: BTreeSet<String>,
|
||||||
prelude_declared_identifiers: BTreeSet<String>,
|
prelude_declared_identifiers: BTreeSet<String>,
|
||||||
stock_filter_quote_usage: StockFilterQuoteUsage,
|
stock_filter_quote_usage: StockFilterQuoteUsage,
|
||||||
|
stock_filter_expr_present: bool,
|
||||||
selection_quote_usage: StockFilterQuoteUsage,
|
selection_quote_usage: StockFilterQuoteUsage,
|
||||||
stock_rolling_requirements: StockRollingRequirements,
|
stock_rolling_requirements: StockRollingRequirements,
|
||||||
stock_extra_factors_required: bool,
|
stock_extra_factors_required: bool,
|
||||||
@@ -1259,6 +1260,7 @@ impl PlatformExprStrategy {
|
|||||||
Self::extract_identifier_candidates(&normalized_prelude);
|
Self::extract_identifier_candidates(&normalized_prelude);
|
||||||
let prelude_declared_identifiers = Self::declared_prelude_identifiers(&config.prelude);
|
let prelude_declared_identifiers = Self::declared_prelude_identifiers(&config.prelude);
|
||||||
let normalized_stock_filter_expr = Self::normalize_expr(&config.stock_filter_expr);
|
let normalized_stock_filter_expr = Self::normalize_expr(&config.stock_filter_expr);
|
||||||
|
let stock_filter_expr_present = !normalized_stock_filter_expr.is_empty();
|
||||||
let stock_filter_quote_usage =
|
let stock_filter_quote_usage =
|
||||||
Self::stock_filter_quote_usage_for_expr(&normalized_stock_filter_expr);
|
Self::stock_filter_quote_usage_for_expr(&normalized_stock_filter_expr);
|
||||||
let selection_quote_usage =
|
let selection_quote_usage =
|
||||||
@@ -1302,6 +1304,7 @@ impl PlatformExprStrategy {
|
|||||||
prelude_identifier_candidates,
|
prelude_identifier_candidates,
|
||||||
prelude_declared_identifiers,
|
prelude_declared_identifiers,
|
||||||
stock_filter_quote_usage,
|
stock_filter_quote_usage,
|
||||||
|
stock_filter_expr_present,
|
||||||
selection_quote_usage,
|
selection_quote_usage,
|
||||||
stock_rolling_requirements,
|
stock_rolling_requirements,
|
||||||
stock_extra_factors_required,
|
stock_extra_factors_required,
|
||||||
@@ -8820,7 +8823,7 @@ impl PlatformExprStrategy {
|
|||||||
day: &DayExpressionState,
|
day: &DayExpressionState,
|
||||||
stock: &StockExpressionState,
|
stock: &StockExpressionState,
|
||||||
) -> Result<bool, BacktestError> {
|
) -> Result<bool, BacktestError> {
|
||||||
if self.config.stock_filter_expr.trim().is_empty() {
|
if !self.stock_filter_expr_present {
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
match self.eval_bool(ctx, &self.config.stock_filter_expr, day, Some(stock), None) {
|
match self.eval_bool(ctx, &self.config.stock_filter_expr, day, Some(stock), None) {
|
||||||
@@ -9064,6 +9067,9 @@ impl PlatformExprStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn universe_exclude_reason(excludes: &[String], symbol: &str) -> Option<&'static str> {
|
fn universe_exclude_reason(excludes: &[String], symbol: &str) -> Option<&'static str> {
|
||||||
|
if excludes.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
let normalized_symbol = symbol.trim().to_ascii_lowercase();
|
let normalized_symbol = symbol.trim().to_ascii_lowercase();
|
||||||
if normalized_symbol.is_empty() {
|
if normalized_symbol.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
@@ -9085,8 +9091,15 @@ impl PlatformExprStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn symbol_is_bjse(symbol: &str) -> bool {
|
fn symbol_is_bjse(symbol: &str) -> bool {
|
||||||
let normalized = symbol.trim().to_ascii_uppercase();
|
let normalized = symbol.trim();
|
||||||
normalized.ends_with(".BJ") || normalized.ends_with(".BSE") || normalized.ends_with(".BE")
|
normalized
|
||||||
|
.get(normalized.len().saturating_sub(3)..)
|
||||||
|
.is_some_and(|suffix| {
|
||||||
|
suffix.eq_ignore_ascii_case(".BJ") || suffix.eq_ignore_ascii_case(".BE")
|
||||||
|
})
|
||||||
|
|| normalized
|
||||||
|
.get(normalized.len().saturating_sub(4)..)
|
||||||
|
.is_some_and(|suffix| suffix.eq_ignore_ascii_case(".BSE"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stock_numeric_field_value(
|
fn stock_numeric_field_value(
|
||||||
@@ -12257,6 +12270,20 @@ mod tests {
|
|||||||
PlatformExprStrategy::universe_exclude_reason(&excludes, "300001.SZ"),
|
PlatformExprStrategy::universe_exclude_reason(&excludes, "300001.SZ"),
|
||||||
None
|
None
|
||||||
);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
PlatformExprStrategy::universe_exclude_reason(&[], " 920508.bj "),
|
||||||
|
None
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bjse_symbol_detection_is_case_insensitive_without_normalizing_all_symbols() {
|
||||||
|
assert!(PlatformExprStrategy::symbol_is_bjse("920508.BJ"));
|
||||||
|
assert!(PlatformExprStrategy::symbol_is_bjse(" 920508.bj "));
|
||||||
|
assert!(PlatformExprStrategy::symbol_is_bjse("430001.BSE"));
|
||||||
|
assert!(PlatformExprStrategy::symbol_is_bjse("430001.be"));
|
||||||
|
assert!(!PlatformExprStrategy::symbol_is_bjse("688001.SH"));
|
||||||
|
assert!(!PlatformExprStrategy::symbol_is_bjse("BJ"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user