减少选股状态热路径字符串分配
This commit is contained in:
@@ -986,6 +986,7 @@ pub struct PlatformExprStrategy {
|
||||
prelude_identifier_candidates: BTreeSet<String>,
|
||||
prelude_declared_identifiers: BTreeSet<String>,
|
||||
stock_filter_quote_usage: StockFilterQuoteUsage,
|
||||
stock_filter_expr_present: bool,
|
||||
selection_quote_usage: StockFilterQuoteUsage,
|
||||
stock_rolling_requirements: StockRollingRequirements,
|
||||
stock_extra_factors_required: bool,
|
||||
@@ -1259,6 +1260,7 @@ impl PlatformExprStrategy {
|
||||
Self::extract_identifier_candidates(&normalized_prelude);
|
||||
let prelude_declared_identifiers = Self::declared_prelude_identifiers(&config.prelude);
|
||||
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 =
|
||||
Self::stock_filter_quote_usage_for_expr(&normalized_stock_filter_expr);
|
||||
let selection_quote_usage =
|
||||
@@ -1302,6 +1304,7 @@ impl PlatformExprStrategy {
|
||||
prelude_identifier_candidates,
|
||||
prelude_declared_identifiers,
|
||||
stock_filter_quote_usage,
|
||||
stock_filter_expr_present,
|
||||
selection_quote_usage,
|
||||
stock_rolling_requirements,
|
||||
stock_extra_factors_required,
|
||||
@@ -8820,7 +8823,7 @@ impl PlatformExprStrategy {
|
||||
day: &DayExpressionState,
|
||||
stock: &StockExpressionState,
|
||||
) -> Result<bool, BacktestError> {
|
||||
if self.config.stock_filter_expr.trim().is_empty() {
|
||||
if !self.stock_filter_expr_present {
|
||||
return Ok(true);
|
||||
}
|
||||
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> {
|
||||
if excludes.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let normalized_symbol = symbol.trim().to_ascii_lowercase();
|
||||
if normalized_symbol.is_empty() {
|
||||
return None;
|
||||
@@ -9085,8 +9091,15 @@ impl PlatformExprStrategy {
|
||||
}
|
||||
|
||||
fn symbol_is_bjse(symbol: &str) -> bool {
|
||||
let normalized = symbol.trim().to_ascii_uppercase();
|
||||
normalized.ends_with(".BJ") || normalized.ends_with(".BSE") || normalized.ends_with(".BE")
|
||||
let normalized = symbol.trim();
|
||||
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(
|
||||
@@ -12257,6 +12270,20 @@ mod tests {
|
||||
PlatformExprStrategy::universe_exclude_reason(&excludes, "300001.SZ"),
|
||||
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]
|
||||
|
||||
Reference in New Issue
Block a user