Skip to content

Commit

Permalink
cache_vrt: Avoid making unnecessary copies of strings
Browse files Browse the repository at this point in the history
  • Loading branch information
nigoroll committed Feb 11, 2025
1 parent c0eadd4 commit a055c50
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
19 changes: 5 additions & 14 deletions bin/varnishd/cache/cache_vrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,6 @@ VRT_synth(VRT_CTX, VCL_INT code, VCL_STRING reason)
return;
}

if (reason && !WS_Allocated(ctx->ws, reason, -1)) {
reason = WS_Copy(ctx->ws, reason, -1);
if (!reason) {
VRT_fail(ctx, "Workspace overflow");
return;
}
}

if (ctx->req == NULL) {
CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
ctx->bo->err_code = (uint16_t)code;
Expand Down Expand Up @@ -445,12 +437,11 @@ VRT_StrandsWS(struct ws *ws, const char *h, VCL_STRANDS s)
}
}

if (q == NULL) {
if (h == NULL)
return ("");
if (WS_Allocated(ws, h, -1))
return (h);
} else if (h == NULL && WS_Allocated(ws, q, -1)) {
if (q == NULL && h == NULL)
return ("");
if (q == NULL)
return (h);
if (h == NULL) {
for (i++; i < s->n; i++)
if (s->p[i] != NULL && *s->p[i] != '\0')
break;
Expand Down
6 changes: 0 additions & 6 deletions vmod/vmod_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,6 @@ xyzzy_concatenate(VRT_CTX, VCL_STRANDS s)

CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
r = VRT_StrandsWS(ctx->ws, NULL, s);
if (r != NULL && *r != '\0')
AN(WS_Allocated(ctx->ws, r, strlen(r) + 1));
return (r);
}

Expand All @@ -657,8 +655,6 @@ xyzzy_collect(VRT_CTX, VCL_STRANDS s)

CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
r = VRT_STRANDS_string(ctx, s);
if (r != NULL && *r != '\0')
AN(WS_Allocated(ctx->ws, r, strlen(r) + 1));
return (r);
}

Expand Down Expand Up @@ -690,8 +686,6 @@ xyzzy_sethdr(VRT_CTX, VCL_HEADER hdr, VCL_STRANDS s)
VSLbs(ctx->vsl, SLT_LostHeader,
TOSTRAND(hdr->what + 1));
} else {
if (*b != '\0')
AN(WS_Allocated(hp->ws, b, strlen(b) + 1));
http_Unset(hp, hdr->what);
http_SetHeader(hp, b);
}
Expand Down

0 comments on commit a055c50

Please sign in to comment.