fix(cpu): use constants for CPU frequency fix values#637
Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/eaglefrom Apr 8, 2026
Merged
fix(cpu): use constants for CPU frequency fix values#637deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/eaglefrom
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/eaglefrom
Conversation
Replace hardcoded frequency strings with named macros to improve code maintainability. Separate the handling logic for kSpecialType9 (2.695GHz) from kSpecialType5/6/7 (2.189GHz) to allow different frequency fix values. log: use constants for CPU frequency fix values pms: https://pms.uniontech.com/bug-view-355551.html
Reviewer's GuideRefactors CPU frequency correction logic by introducing named constants for special device types and separating kSpecialType9 handling from kSpecialType5/6/7, while updating license year ranges. Class diagram for updated DeviceCpu CPU frequency fix logicclassDiagram
class DeviceCpu {
+void setCpuInfo(QMap_mapLscpu, QMap_mapCpuinfo)
-QString m_Frequency
-QString m_MaxFrequency
}
class Common {
<<static>> int specialComType
<<enum>> kSpecialType5
<<enum>> kSpecialType6
<<enum>> kSpecialType7
<<enum>> kSpecialType9
}
class CpuFrequencyFixConstants {
<<macro>> CPU_FREQ_TYPE5_7_OLD
<<macro>> CPU_FREQ_TYPE5_7_NEW
<<macro>> CPU_MAXFREQ_TYPE5_7_OLD
<<macro>> CPU_MAXFREQ_TYPE5_7_NEW
<<macro>> CPU_FREQ_TYPE9_OLD
<<macro>> CPU_FREQ_TYPE9_NEW
<<macro>> CPU_MAXFREQ_TYPE9_OLD
<<macro>> CPU_MAXFREQ_TYPE9_NEW
}
DeviceCpu ..> Common : uses specialComType
DeviceCpu ..> CpuFrequencyFixConstants : uses macros in setCpuInfo
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The CPU frequency fix values are only used inside DeviceCpu::setCpuInfo, so consider moving the string constants out of the header and into the .cpp file (e.g., as
constexprvariables in an anonymous namespace) to avoid polluting the global macro namespace and recompiling dependents unnecessarily. - Instead of using
#definefor the frequency strings, prefer typed constants (constexpr autoorstatic const QString) to gain type safety, scope control, and debugger friendliness.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The CPU frequency fix values are only used inside DeviceCpu::setCpuInfo, so consider moving the string constants out of the header and into the .cpp file (e.g., as `constexpr` variables in an anonymous namespace) to avoid polluting the global macro namespace and recompiling dependents unnecessarily.
- Instead of using `#define` for the frequency strings, prefer typed constants (`constexpr auto` or `static const QString`) to gain type safety, scope control, and debugger friendliness.
## Individual Comments
### Comment 1
<location path="deepin-devicemanager/src/DeviceManager/DeviceCpu.h" line_range="11-21" />
<code_context>
#include "commonfunction.h"
+
+// kSpecialType5/6/7
+#define CPU_FREQ_TYPE5_7_OLD "2.189"
+#define CPU_FREQ_TYPE5_7_NEW "2.188"
+#define CPU_MAXFREQ_TYPE5_7_OLD "2189"
+#define CPU_MAXFREQ_TYPE5_7_NEW "2188"
+
+// kSpecialType9
+#define CPU_FREQ_TYPE9_OLD "2.695"
+#define CPU_FREQ_TYPE9_NEW "2.7"
+#define CPU_MAXFREQ_TYPE9_OLD "2695"
+#define CPU_MAXFREQ_TYPE9_NEW "2700"
+
/**
</code_context>
<issue_to_address>
**suggestion:** Prefer typed constants over preprocessor macros for these frequency strings.
Since these are configuration constants, consider replacing the `#define`s with `constexpr auto` or `const QString` (e.g., in an anonymous or dedicated namespace). That keeps them out of the global macro space, maintains type safety, and avoids name collisions if these identifiers appear elsewhere.
```suggestion
namespace {
constexpr auto CPU_FREQ_TYPE5_7_OLD = "2.189";
constexpr auto CPU_FREQ_TYPE5_7_NEW = "2.188";
constexpr auto CPU_MAXFREQ_TYPE5_7_OLD = "2189";
constexpr auto CPU_MAXFREQ_TYPE5_7_NEW = "2188";
constexpr auto CPU_FREQ_TYPE9_OLD = "2.695";
constexpr auto CPU_FREQ_TYPE9_NEW = "2.7";
constexpr auto CPU_MAXFREQ_TYPE9_OLD = "2695";
constexpr auto CPU_MAXFREQ_TYPE9_NEW = "2700";
} // namespace
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
max-lvs
approved these changes
Apr 7, 2026
GongHeng2017
approved these changes
Apr 7, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, GongHeng2017, max-lvs 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 |
Contributor
Author
|
/forcemerge |
Contributor
|
This pr force merged! (status: unstable) |
7a7b477
into
linuxdeepin:develop/eagle
20 of 22 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace hardcoded frequency strings with named macros to improve code maintainability. Separate the handling logic for kSpecialType9 (2.695GHz) from kSpecialType5/6/7 (2.189GHz) to allow different frequency fix values.
log: use constants for CPU frequency fix values
pms: https://pms.uniontech.com/bug-view-355551.html
Summary by Sourcery
Use named CPU frequency constants and adjust special-type handling for CPU frequency fixes.
Bug Fixes:
Enhancements: