Skip to content

Commit da495e8

Browse files
committed
Enhance performance
1 parent 6469584 commit da495e8

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

MemoryCleaner.pro

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,22 @@ TEMPLATE = app
88

99
QMAKE_LFLAGS_RELEASE += -Wl,-s
1010
QMAKE_CFLAGS_RELEASE -= -O0
11-
QMAKE_CFLAGS_RELEASE += -O2
11+
QMAKE_CFLAGS_RELEASE += -O3
1212
QMAKE_CXXFLAGS_RELEASE -= -O0
13-
QMAKE_CXXFLAGS_RELEASE += -O2
13+
QMAKE_CXXFLAGS_RELEASE += -O3
1414

1515
QMAKE_CXXFLAGS_RELEASE += -ffunction-sections -fdata-sections
1616
QMAKE_LFLAGS_RELEASE += -Wl,--gc-sections
1717

18+
QMAKE_CXXFLAGS_RELEASE += -flto -fno-fat-lto-objects
19+
QMAKE_LFLAGS_RELEASE += -flto
20+
21+
QMAKE_CXXFLAGS_RELEASE += -march=native
22+
23+
QMAKE_CXXFLAGS_RELEASE += -fomit-frame-pointer
24+
25+
QMAKE_CXXFLAGS_RELEASE += -DNDEBUG
26+
1827
win32 {
1928
QMAKE_LFLAGS_RELEASE += -Wl,--enable-stdcall-fixup
2029
DEFINES += WIN32_LEAN_AND_MEAN

src/mainwindow.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ void MainWindow::on_btnCleanNow_clicked()
424424
memAfter.dwLength = sizeof(MEMORYSTATUSEX);
425425
GlobalMemoryStatusEx(&memAfter);
426426

427-
double cleaned = (memAfter.ullAvailPhys - memBefore.ullAvailPhys) / (1024.0 * 1024);
427+
double cleaned = ((long long)memAfter.ullAvailPhys - (long long)memBefore.ullAvailPhys) / (1024.0 * 1024);
428428
ui->textBrowser->append(tr("[%1] 已清理内存: %2 MB")
429429
.arg(QDateTime::currentDateTime().toString("hh:mm:ss"))
430430
.arg(cleaned, 0, 'f', 1));
@@ -791,16 +791,14 @@ void MainWindow::setAutoStart(bool enable)
791791
LPCWSTR keyPath = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
792792
LPCWSTR appName = L"MemoryCleaner";
793793

794-
// 获取应用程序的完整路径
794+
795795
wchar_t exePath[MAX_PATH];
796796
GetModuleFileNameW(NULL, exePath, MAX_PATH);
797797

798798
if (RegOpenKeyExW(HKEY_CURRENT_USER, keyPath, 0, KEY_WRITE, &hKey) == ERROR_SUCCESS) {
799799
if (enable) {
800-
// 添加开机自启动
801800
RegSetValueExW(hKey, appName, 0, REG_SZ, (BYTE*)exePath, (wcslen(exePath) + 1) * sizeof(wchar_t));
802801
} else {
803-
// 删除开机自启动
804802
RegDeleteValueW(hKey, appName);
805803
}
806804
RegCloseKey(hKey);
@@ -810,7 +808,7 @@ void MainWindow::setAutoStart(bool enable)
810808
ui->actionAutoStart->setChecked(enable);
811809
}
812810

813-
// 检查是否已设置开机自启动
811+
814812
bool MainWindow::isAutoStartEnabled()
815813
{
816814
HKEY hKey;
@@ -849,13 +847,13 @@ void MainWindow::onEnableMessageTriggered()
849847
bool enabled = ui->actionEnableMessage->isChecked();
850848
enableMessage = enabled;
851849

852-
// 保存设置
850+
853851
QString iniPath = QCoreApplication::applicationDirPath() + "/settings.ini";
854852
QSettings settings(iniPath, QSettings::IniFormat);
855853
settings.setValue("enableMessage", enabled);
856854
settings.sync();
857855

858-
// 显示提示消息(仅在开启通知时显示)
856+
859857
if (enabled) {
860858
QString message = enabled ? tr("已开启通知消息") : tr("已关闭通知消息");
861859
trayIcon->showMessage("MemoryCleaner", message, QSystemTrayIcon::Information, 2000);

0 commit comments

Comments
 (0)