mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
[data] Premature optimisation. One memacpy less for base64 encoded data.
This commit is contained in:
parent
01c232c4e1
commit
267948b2e8
@ -116,7 +116,7 @@ data_protocol_handler(struct connection *conn)
|
|||||||
{
|
{
|
||||||
struct uri *uri = conn->uri;
|
struct uri *uri = conn->uri;
|
||||||
struct cache_entry *cached = get_cache_entry(uri);
|
struct cache_entry *cached = get_cache_entry(uri);
|
||||||
unsigned char *data_start, *data;
|
unsigned char *data_start, *data = NULL;
|
||||||
int base64 = 0;
|
int base64 = 0;
|
||||||
int decodedlen = 0;
|
int decodedlen = 0;
|
||||||
int datalen;
|
int datalen;
|
||||||
@ -137,14 +137,8 @@ data_protocol_handler(struct connection *conn)
|
|||||||
/* Allocate the data string because URI decoding will possibly modify
|
/* Allocate the data string because URI decoding will possibly modify
|
||||||
* it. */
|
* it. */
|
||||||
datalen = uri->datalen - (data_start - uri->data);
|
datalen = uri->datalen - (data_start - uri->data);
|
||||||
data = memacpy(data_start, datalen);
|
|
||||||
if (!data) {
|
|
||||||
abort_connection(conn, connection_state(S_OUT_OF_MEM));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (base64) {
|
if (base64) {
|
||||||
unsigned char *decoded = base64_decode_bin(data, datalen, &decodedlen);
|
unsigned char *decoded = base64_decode_bin(data_start, datalen, &decodedlen);
|
||||||
|
|
||||||
if (!decoded) {
|
if (!decoded) {
|
||||||
abort_connection(conn, connection_state(S_OUT_OF_MEM));
|
abort_connection(conn, connection_state(S_OUT_OF_MEM));
|
||||||
@ -153,6 +147,12 @@ data_protocol_handler(struct connection *conn)
|
|||||||
|
|
||||||
mem_free_set(&data, decoded);
|
mem_free_set(&data, decoded);
|
||||||
} else {
|
} else {
|
||||||
|
data = memacpy(data_start, datalen);
|
||||||
|
|
||||||
|
if (!data) {
|
||||||
|
abort_connection(conn, connection_state(S_OUT_OF_MEM));
|
||||||
|
return;
|
||||||
|
}
|
||||||
decode_uri(data);
|
decode_uri(data);
|
||||||
/* Use strlen() to get the correct decoded length */
|
/* Use strlen() to get the correct decoded length */
|
||||||
decodedlen = strlen(data);
|
decodedlen = strlen(data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user