refactor ParsedIntent to use pimpl pattern#318
Conversation
Johnson-zs
commented
Jun 23, 2026
- refactor: convert HighlightOptions to Pimpl pattern
- fix: refactor ParsedIntent to use pimpl pattern
Changed the HighlightOptions from a plain struct to a Pimpl (Pointer to Implementation) class pattern with QSharedDataPointer for implicit sharing (COW - Copy On Write) support. This provides better ABI stability and encapsulation. Key changes: 1. Converted plain struct to class with private implementation 2. Added getter/setter methods for all properties 3. Implemented proper copy/move semantics 4. Added QSharedDataPointer for efficient copying 5. Updated all usage sites to use new accessor methods The change was made to: 1. Improve ABI stability - changes to implementation won't break binary compatibility 2. Enable future extensibility without breaking changes 3. Reduce header dependencies through proper encapsulation 4. Allow implicit sharing for efficient copying 5. Better control over member access The Pimpl pattern gives better binary compatibility guarantees and prepares the codebase for future extensions while maintaining the same functionality. Log: Updated HighlightOptions implementation to use Pimpl pattern Influence: 1. Verify snippet highlight extraction still works in file search results 2. Test content preview generation in search results 3. Check search functionality in file manager 4. Validate highlighter works with different preview length settings 5. Verify HTML wrapping option works when enabled refactor: 将 HighlightOptions 转换为 Pimpl 模式 将 HighlightOptions 从普通结构体转换为使用 Pimpl(Pointer to Implementation)模式和 QSharedDataPointer 支持隐式共享(COW - 写入时复 制)的类。这提供了更好的ABI稳定性和封装性。 主要变更: 1. 将普通结构体转换为具有私有实现的类 2. 为所有属性添加getter/setter方法 3. 实现适当的拷贝/移动语义 4. 添加QSharedDataPointer以支持高效复制 5. 更新所有使用点以使用新的访问方法 此次更改的目的: 1. 提高ABI稳定性 - 实现更改不会破坏二进制兼容性 2. 支持未来扩展性而无需破坏性更改 3. 通过适当封装减少头文件依赖 4. 允许隐式共享以提高复制效率 5. 更好地控制成员访问 Pimpl模式提供了更好的二进制兼容性保证,并使代码库准备好未来扩展,同时保 持相同功能。 Log: 更新 HighlightOptions 实现以使用 Pimpl 模式 Influence: 1. 验证文件搜索结果中的片段高亮提取功能仍正常工作 2. 测试搜索结果中内容预览生成 3. 检查文件管理器中的搜索功能 4. 验证高亮器在不同的预览长度设置下工作正常 5. 验证HTML包装选项在启用时正常工作
1. Change ParsedIntent from struct to class with QSharedDataPointer 2. Add private implementation class ParsedIntentPrivate 3. Implement proper copy/move semantics 4. Add getter/setter methods for all fields 5. Update all usage points to use new accessors Influence: 1. All test cases involving ParsedIntent need to be verified 2. Semantic search functionality should work as before 3. Pay attention to deep copy behavior and performance impact fix: 重构 ParsedIntent 使用 pimpl 模式 1. 将 ParsedIntent 从结构体改为使用 QSharedDataPointer 的类 2. 添加私有实现类 ParsedIntentPrivate 3. 实现正确的拷贝/移动语义 4. 为所有字段添加 getter/setter 方法 5. 更新所有使用点以使用新的访问器 影响: 1. 需要验证所有涉及 ParsedIntent 的测试用例 2. 语义搜索功能应保持原有行为 3. 注意深拷贝行为和性能影响
There was a problem hiding this comment.
Sorry @Johnson-zs, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Johnson-zs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
deepin pr auto review★ 总体评分:100分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // src/dfm-search/dfm-search-lib/semantic/extractors/actionextractor.cpp
// 优化连续调用getter的代码片段,提升可读性并避免冗余的detach检查
void ActionExtractor::extract(const QString &input, ParsedIntent &intent)
{
// ... 前置逻辑省略 ...
// ── IM received files ──
if (isImReceive) {
const QStringList resolvedPaths = resolveImReceivedPaths();
if (!resolvedPaths.isEmpty()) {
// 使用局部引用缓存getter返回值,避免重复调用
QStringList &dirs = intent.searchDirectories();
for (const QString &path : resolvedPaths) {
if (!dirs.contains(path)) {
dirs.append(path);
}
}
MatchSpan span;
span.start = m.capturedStart();
span.end = m.capturedEnd();
span.ruleId = ruleIds[i];
intent.consumedSpans().append(span);
}
continue;
}
// ... 后置逻辑省略 ...
} |