Skip to content

Commit

Permalink
fixup! job-info: support job info CURRENT lookup flag
Browse files Browse the repository at this point in the history
This is a minor optimization to avoid an extra json_dumps() call, doesn't
look that pretty, is ok?
  • Loading branch information
chu11 committed Feb 1, 2024
1 parent 042e75e commit a421501
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/modules/job-info/lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static int lookup_current (struct lookup_ctx *l,
flux_future_t *fall,
const char *key,
const char *value,
char **current_value)
json_t **current_object)
{
flux_future_t *f_eventlog;
const char *s_eventlog;
Expand All @@ -168,7 +168,6 @@ static int lookup_current (struct lookup_ctx *l,
size_t index;
json_t *entry;
const char *update_event_name = NULL;
char *value_object_str = NULL;
int save_errno;

if (streq (key, "R"))
Expand Down Expand Up @@ -208,19 +207,14 @@ static int lookup_current (struct lookup_ctx *l,
}
}

if (!(value_object_str = json_dumps (value_object, 0)))
goto error;

(*current_value) = value_object_str;
(*current_object) = value_object;
json_decref (eventlog);
json_decref (value_object);
return 0;

error:
save_errno = errno;
json_decref (eventlog);
json_decref (value_object);
free (value_object_str);
errno = save_errno;
return -1;
}
Expand Down Expand Up @@ -289,9 +283,25 @@ static void info_lookup_continuation (flux_future_t *fall, void *arg)

if ((l->flags & FLUX_JOB_LOOKUP_CURRENT)
&& streq (keystr, "R")) {
if (lookup_current (l, fall, keystr, s, &current_value) < 0)
json_t *current_object = NULL;
if (lookup_current (l, fall, keystr, s, &current_object) < 0)
goto error;
s = current_value;
/* tiny optimization, to skip unnecessary json_dumps() and
* fallthrough to code below
*/
if (l->flags & FLUX_JOB_LOOKUP_JSON_DECODE) {
val = current_object;
goto store;
}
else {
if (!(current_value = json_dumps (current_object, 0))) {
errno = ENOMEM;
json_decref (current_object);
goto error;
}
s = current_value;
json_decref (current_object);
}
}

/* check for JSON_DECODE flag last, as changes above could affect
Expand All @@ -309,6 +319,7 @@ static void info_lookup_continuation (flux_future_t *fall, void *arg)
goto enomem;
}

store:
if (json_object_set_new (o, keystr, val) < 0) {
json_decref (val);
goto enomem;
Expand Down

0 comments on commit a421501

Please sign in to comment.