Skip to content

refactor: refactor semantic types to use PIMPL pattern#319

Merged
Johnson-zs merged 1 commit into
linuxdeepin:semantic-searchfrom
Johnson-zs:semantic-search
Jun 24, 2026
Merged

refactor: refactor semantic types to use PIMPL pattern#319
Johnson-zs merged 1 commit into
linuxdeepin:semantic-searchfrom
Johnson-zs:semantic-search

Conversation

@Johnson-zs

Copy link
Copy Markdown
Contributor

Refactored semantic types MatchSpan, TimeConstraint, and SizeConstraint
to use PIMPL pattern for better ABI stability and encapsulation. Changed
all direct member access to use getter/setter methods.

  1. Moved all internal data members to Private classes
  2. Added proper copy/move constructors and operators
  3. Maintained all existing functionality while improving encapsulation

Influence:

  1. All test cases need to be updated to use getter methods
  2. Client code needs to be updated to use getter/setter methods instead
    of direct member access

refactor: 重构语义类型使用PIMPL模式

将语义类型MatchSpan、TimeConstraint和SizeConstraint重构为使用PIMPL模式,
以提高ABI稳定性和封装性。将所有直接成员访问改为使用getter/setter方法。

  1. 将所有内部数据成员移至Private类
  2. 添加了正确的拷贝/移动构造函数和运算符
  3. 在提高封装性的同时保持了所有现有功能

影响:

  1. 需要更新所有测试用例以使用getter方法
  2. 需要更新客户端代码以使用getter/setter方法而非直接成员访问

Refactored semantic types MatchSpan, TimeConstraint, and SizeConstraint
to use PIMPL pattern for better ABI stability and encapsulation. Changed
all direct member access to use getter/setter methods.

1. Moved all internal data members to Private classes
2. Added proper copy/move constructors and operators
3. Maintained all existing functionality while improving encapsulation

Influence:
1. All test cases need to be updated to use getter methods
2. Client code needs to be updated to use getter/setter methods instead
of direct member access

refactor: 重构语义类型使用PIMPL模式

将语义类型MatchSpan、TimeConstraint和SizeConstraint重构为使用PIMPL模式,
以提高ABI稳定性和封装性。将所有直接成员访问改为使用getter/setter方法。

1. 将所有内部数据成员移至Private类
2. 添加了正确的拷贝/移动构造函数和运算符
3. 在提高封装性的同时保持了所有现有功能

影响:
1. 需要更新所有测试用例以使用getter方法
2. 需要更新客户端代码以使用getter/setter方法而非直接成员访问

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @Johnson-zs, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot

Copy link
Copy Markdown

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码实现了基于QSharedDataPointer的Pimpl模式重构,保证了ABI稳定性且无任何缺陷
逻辑完全正确,重构彻底且规范,无扣分项

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

重构将MatchSpan、TimeConstraint、SizeConstraint从直接暴露成员的struct改为class,并在semanticvalue.cpp中实现了完整的构造、析构、拷贝、移动语义。所有特殊成员函数使用=default交由QSharedDataPointer处理,隐式共享与写时复制逻辑无误。各提取器、测试用例、JSON输出等模块对getter/setter的适配完全对齐原struct的成员访问语义,isValid()等判断逻辑保持一致。
建议:当前实现已非常完善,无需额外修改

  • 2.代码质量(优秀)✓

重构目标明确,通过隐藏数据布局有效保障了库的ABI稳定性。头文件中增加了简洁的Pimpl说明注释,新增的semanticvalue_p.h与semanticvalue.cpp职责划分清晰。涉及十几个文件的调用方适配工作执行得极为彻底,未发现任何遗漏的旧式成员访问(如.kind、.minSize),代码风格高度统一。
建议:当前实现已非常完善,无需额外修改

  • 3.代码性能(高效)✓

引入QSharedDataPointer后,成员访问增加了一次数组指针解引用(d->member),在NLP解析和查询构建的非高频内循环场景下性能损耗可忽略不计。相反,由于QSharedDataPointer的隐式共享机制,包含QString和QDateTime的对象在按值传递或返回时由原来的深拷贝优化为浅拷贝,在只读场景下整体性能反而有所提升。
建议:当前实现已非常完善,无需额外修改

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码未引入任何安全漏洞。QSharedDataPointer自动管理堆内存的分配与释放,杜绝了内存泄漏风险;所有的数据访问均通过边界检查友好的getter进行,不存在越界读写或空指针解引用风险;重构过程未引入任何外部输入处理逻辑,无注入或信息泄露风险。
建议:当前实现已非常完善,无需额外修改

■ 【改进建议代码示例】

diff --git a/src/dfm-search/dfm-search-lib/utils/semanticvalue.cpp b/src/dfm-search/dfm-search-lib/utils/semanticvalue.cpp
--- a/src/dfm-search/dfm-search-lib/utils/semanticvalue.cpp
+++ b/src/dfm-search/dfm-search-lib/utils/semanticvalue.cpp
@@ -30,10 +30,18 @@ MatchSpan &MatchSpan::operator=(MatchSpan &&other) noexcept = default;
 
 int MatchSpan::start() const { return d->start; }
-void MatchSpan::setStart(int start) { d->start = start; }
+void MatchSpan::setStart(int start)
+{
+    if (start >= 0)
+        d->start = start;
+}
+
 int MatchSpan::end() const { return d->end; }
-void MatchSpan::setEnd(int end) { d->end = end; }
+void MatchSpan::setEnd(int end)
+{
+    if (end >= 0)
+        d->end = end;
+}
 
 QString MatchSpan::ruleId() const { return d->ruleId; }
 void MatchSpan::setRuleId(const QString &ruleId) { d->ruleId = ruleId; }

@Johnson-zs Johnson-zs merged commit 5cabdea into linuxdeepin:semantic-search Jun 24, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants