Skip to content

Commit a055c50

Browse files
committed
cache_vrt: Avoid making unnecessary copies of strings
1 parent c0eadd4 commit a055c50

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

bin/varnishd/cache/cache_vrt.c

+5-14
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,6 @@ VRT_synth(VRT_CTX, VCL_INT code, VCL_STRING reason)
9393
return;
9494
}
9595

96-
if (reason && !WS_Allocated(ctx->ws, reason, -1)) {
97-
reason = WS_Copy(ctx->ws, reason, -1);
98-
if (!reason) {
99-
VRT_fail(ctx, "Workspace overflow");
100-
return;
101-
}
102-
}
103-
10496
if (ctx->req == NULL) {
10597
CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
10698
ctx->bo->err_code = (uint16_t)code;
@@ -445,12 +437,11 @@ VRT_StrandsWS(struct ws *ws, const char *h, VCL_STRANDS s)
445437
}
446438
}
447439

448-
if (q == NULL) {
449-
if (h == NULL)
450-
return ("");
451-
if (WS_Allocated(ws, h, -1))
452-
return (h);
453-
} else if (h == NULL && WS_Allocated(ws, q, -1)) {
440+
if (q == NULL && h == NULL)
441+
return ("");
442+
if (q == NULL)
443+
return (h);
444+
if (h == NULL) {
454445
for (i++; i < s->n; i++)
455446
if (s->p[i] != NULL && *s->p[i] != '\0')
456447
break;

vmod/vmod_debug.c

-6
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,6 @@ xyzzy_concatenate(VRT_CTX, VCL_STRANDS s)
645645

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

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

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

@@ -690,8 +686,6 @@ xyzzy_sethdr(VRT_CTX, VCL_HEADER hdr, VCL_STRANDS s)
690686
VSLbs(ctx->vsl, SLT_LostHeader,
691687
TOSTRAND(hdr->what + 1));
692688
} else {
693-
if (*b != '\0')
694-
AN(WS_Allocated(hp->ws, b, strlen(b) + 1));
695689
http_Unset(hp, hdr->what);
696690
http_SetHeader(hp, b);
697691
}

0 commit comments

Comments
 (0)