Skip to content

Instantly share code, notes, and snippets.

@ywkaras
Created August 2, 2017 18:12
Show Gist options
  • Save ywkaras/7d32688f8a0054df2d4f107891ffde7d to your computer and use it in GitHub Desktop.
Save ywkaras/7d32688f8a0054df2d4f107891ffde7d to your computer and use it in GitHub Desktop.
Code without and with BufferWriter class
Old:
*via_string++ = ' ';
*via_string++ = '[';
// incoming_via can be max MAX_VIA_INDICES+1 long (i.e. around 25 or so)
if (s->txn_conf->insert_request_via_string > 2) { // Highest verbosity
via_string += nstrcpy(via_string, incoming_via);
} else {
memcpy(via_string, incoming_via + VIA_CLIENT, VIA_SERVER - VIA_CLIENT);
via_string += VIA_SERVER - VIA_CLIENT;
}
*via_string++ = ']';
// reserve 4 for " []" and 3 for "])".
if (via_limit - via_string > 4 && s->txn_conf->insert_request_via_string > 3) { // Ultra highest verbosity
*via_string++ = ' ';
*via_string++ = '[';
via_string += write_via_protocol_stack(via_string, via_limit - via_string - 3,
true, proto_buf.data(), n_proto);
*via_string++ = ']';
}
New (via_string is BufferWriter instance):
via_string.l(" [");
// incoming_via can be max MAX_VIA_INDICES+1 long (i.e. around 25 or so)
if (s->txn_conf->insert_request_via_string > 2) { // Highest verbosity
via_string.cstr(incoming_via);
} else {
via_string.sV(incomimg_via, VIA_SERVER - VIA_CLIENT);
}
via_string.c(']');
if (s->txn_conf->insert_request_via_string > 3) { // Ultra highest verbosity
size_t save = via_string.size();
via_string.l(" [");
via_string.auxWrite(
write_via_protocol_stack(via_string.auxBuffer(), via_string.auxCapacity(), true, proto_buf.data(), n_proto));
via_string.c(']');
if (via_string.error()) {
via_string.resize(save);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment