Skip to content

Commit 6ff67e8

Browse files
committed
Memory: refactor, don't cache results
1 parent 0a83423 commit 6ff67e8

File tree

16 files changed

+26
-46
lines changed

16 files changed

+26
-46
lines changed

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,8 @@ set(LIBFASTFETCH_SRC
240240
src/detection/host/host.c
241241
src/detection/locale/locale.c
242242
src/detection/media/media.c
243-
src/detection/memory/memory.c
244243
src/detection/os/os.c
245244
src/detection/packages/packages.c
246-
src/detection/swap/swap.c
247245
src/detection/terminalfont/terminalfont.c
248246
src/detection/terminalshell/terminalshell.c
249247
src/detection/title.c

src/detection/memory/memory.c

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/detection/memory/memory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
#include "detection/storage.h"
77

8-
const FFMemoryStorage* ffDetectMemory();
8+
void ffDetectMemory(FFMemoryStorage* result);
99

1010
#endif

src/detection/memory/memory_apple.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <string.h>
55
#include <mach/mach.h>
66

7-
void ffDetectMemoryImpl(FFMemoryStorage* ram)
7+
void ffDetectMemory(FFMemoryStorage* ram)
88
{
99
ram->bytesTotal = (uint64_t) ffSysctlGetInt64("hw.memsize", 0);
1010
if(ram->bytesTotal == 0)

src/detection/memory/memory_bsd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "memory.h"
22
#include "common/sysctl.h"
33

4-
void ffDetectMemoryImpl(FFMemoryStorage* ram)
4+
void ffDetectMemory(FFMemoryStorage* ram)
55
{
66
uint32_t pageSize = (uint32_t) ffSysctlGetInt("hw.pagesize", 0);
77
if(pageSize == 0)

src/detection/memory/memory_linux.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#include <stdlib.h>
44
#include <string.h>
55

6-
void ffDetectMemoryImpl(FFMemoryStorage* swap)
6+
void ffDetectMemory(FFMemoryStorage* ram)
77
{
88
FILE* meminfo = fopen("/proc/meminfo", "r");
99
if(meminfo == NULL)
1010
{
11-
ffStrbufAppendS(&swap->error, "Failed to open /proc/meminfo");
11+
ffStrbufAppendS(&ram->error, "Failed to open /proc/meminfo");
1212
return;
1313
}
1414

@@ -37,9 +37,9 @@ void ffDetectMemoryImpl(FFMemoryStorage* swap)
3737

3838
fclose(meminfo);
3939

40-
swap->bytesTotal = memTotal * (uint64_t) 1024;
41-
if(swap->bytesTotal == 0)
42-
ffStrbufAppendS(&swap->error, "Failed to read MemTotal");
40+
ram->bytesTotal = memTotal * (uint64_t) 1024;
41+
if(ram->bytesTotal == 0)
42+
ffStrbufAppendS(&ram->error, "Failed to read MemTotal");
4343
else
44-
swap->bytesUsed = (memTotal + shmem - memFree - buffers - cached - sReclaimable) * (uint64_t) 1024;
44+
ram->bytesUsed = (memTotal + shmem - memFree - buffers - cached - sReclaimable) * (uint64_t) 1024;
4545
}

src/detection/memory/memory_windows.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "memory.h"
22

3-
void ffDetectMemoryImpl(FFMemoryStorage* ram)
3+
void ffDetectMemory(FFMemoryStorage* ram)
44
{
55
MEMORYSTATUSEX statex = {
66
.dwLength = sizeof(statex),

src/detection/storage.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ typedef struct FFMemoryStorage
1010
FFstrbuf error;
1111
uint64_t bytesUsed;
1212
uint64_t bytesTotal;
13-
uint8_t percentage;
1413
} FFMemoryStorage;
1514

1615
#endif

src/detection/swap/swap.c

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/detection/swap/swap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
#include "detection/storage.h"
77

8-
const FFMemoryStorage* ffDetectSwap();
8+
void ffDetectSwap(FFMemoryStorage* result);
99

1010
#endif

0 commit comments

Comments
 (0)