Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Tarassov2014-02-15 18:44:24 -0500
committerEugene Tarassov2014-02-15 18:44:24 -0500
commit388ce39e8e45abef16681a0def537895c1c7d87c (patch)
tree9d613593edeed371387e26c823cbe8a04916677a
parentccb041d0eaed9c4fe7a27171d2fa1f6f2bde5834 (diff)
downloadorg.eclipse.tcf.agent-388ce39e8e45abef16681a0def537895c1c7d87c.tar.gz
org.eclipse.tcf.agent-388ce39e8e45abef16681a0def537895c1c7d87c.tar.xz
org.eclipse.tcf.agent-388ce39e8e45abef16681a0def537895c1c7d87c.zip
TCF Agent: faster implementation of json_read_binary_data()1.2_pre_branch
-rw-r--r--agent/tcf/framework/json.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/agent/tcf/framework/json.c b/agent/tcf/framework/json.c
index 4336e77b..62f7d42b 100644
--- a/agent/tcf/framework/json.c
+++ b/agent/tcf/framework/json.c
@@ -640,9 +640,22 @@ void json_read_binary_start(JsonReadBinaryState * state, InputStream * inp) {
size_t json_read_binary_data(JsonReadBinaryState * state, void * buf, size_t len) {
size_t res = 0;
uint8_t * ptr = (uint8_t *)buf;
+ InputStream * inp = state->inp;
+
if (state->encoding == ENCODING_BINARY) {
if (len > (size_t)(state->size_start - state->size_done)) len = state->size_start - state->size_done;
- while (res < len) ptr[res++] = (uint8_t)read_stream(state->inp);
+ while (res < len) {
+ if (inp->cur < inp->end) {
+ size_t n = inp->end - inp->cur;
+ if (n > len - res) n = len - res;
+ memcpy(ptr + res, inp->cur, n);
+ inp->cur += n;
+ res += n;
+ }
+ else {
+ ptr[res++] = (uint8_t)inp->read(inp);
+ }
+ }
}
else {
while (len > 0) {
@@ -662,14 +675,14 @@ size_t json_read_binary_data(JsonReadBinaryState * state, void * buf, size_t len
state->rem = 0;
}
if (len >= 3) {
- size_t i = read_base64(state->inp, (char *)ptr, len);
+ size_t i = read_base64(inp, (char *)ptr, len);
if (i == 0) break;
ptr += i;
len -= i;
res += i;
}
else {
- state->rem = read_base64(state->inp, state->buf, 3);
+ state->rem = read_base64(inp, state->buf, 3);
if (state->rem == 0) break;
}
}

Back to the top