Skip to content

Commit b59c8df

Browse files
committed
Improve code readability
1 parent aa19632 commit b59c8df

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/main.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ bool parseAndPrintJson(const char* data, uint16_t len) {
5858
} else {
5959
result = true;
6060
JsonNode* root = json_parser_get_root(parser);
61-
printJson(json_node_get_object(root));
61+
JsonObject* object = json_node_get_object(root);
62+
printJson(object);
6263
}
6364

6465
g_object_unref(parser);
@@ -73,20 +74,23 @@ void printTimestamp(struct timeval tv) {
7374
baseMicroSeconds = tv.tv_usec;
7475
}
7576

76-
long seconds = tv.tv_sec;
77+
long secondsTotal = tv.tv_sec;
7778
long microSeconds = tv.tv_usec;
7879

7980
if (sArgs.useStopwatchFormat()) {
80-
seconds -= baseSeconds;
81+
secondsTotal -= baseSeconds;
8182
microSeconds -= baseMicroSeconds;
8283

8384
if (microSeconds < 0) {
8485
microSeconds += 1000000;
85-
seconds--;
86+
secondsTotal--;
8687
}
8788
}
8889

89-
printf("%02ld:%02ld:%02ld.%06ld ", (seconds / 3600) % 24, (seconds / 60) % 60, seconds % 60, microSeconds);
90+
int hours = (secondsTotal / 3600) % 24;
91+
int minutes = (secondsTotal / 60) % 60;
92+
int seconds = secondsTotal % 60;
93+
printf("%02d:%02d:%02d.%06ld ", hours, minutes, seconds, microSeconds);
9094
}
9195

9296
void printHttpRequestTitle(const char* data, int /* len */) {

src/print.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,11 @@ void printJsonObject(JsonObject* object, unsigned int* indent) {
130130
GList* members = json_object_get_members(object);
131131

132132
for (element = members; element; element = element->next) {
133+
JsonNode* node = json_object_get_member(object, (const gchar*) element->data);
134+
133135
printIndent(*indent);
134136
printf("\"%s\":", (const gchar*) element->data);
135-
printJsonNode(json_object_get_member(object, (const gchar*) element->data), indent);
137+
printJsonNode(node, indent);
136138

137139
if (element->next != NULL) {
138140
printf(",");

0 commit comments

Comments
 (0)