Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Tarassov2013-08-28 02:42:35 -0400
committerEugene Tarassov2013-08-28 02:42:35 -0400
commit3374548567e5255d17c558bad2235a9a325d0466 (patch)
tree62cdb990cee8bc19460aaa7aa5c9801b4caf119a
parent1bbb436cdf19d40441abafc2ff5f6f1e09db6502 (diff)
downloadorg.eclipse.tcf.agent-3374548567e5255d17c558bad2235a9a325d0466.tar.gz
org.eclipse.tcf.agent-3374548567e5255d17c558bad2235a9a325d0466.tar.xz
org.eclipse.tcf.agent-3374548567e5255d17c558bad2235a9a325d0466.zip
TCF Agent: performance improvements in the protocol handling code
-rw-r--r--agent/tcf/framework/json.c58
-rw-r--r--agent/tcf/framework/protocol.c4
2 files changed, 36 insertions, 26 deletions
diff --git a/agent/tcf/framework/json.c b/agent/tcf/framework/json.c
index 6f80a6f1..4b35f5b8 100644
--- a/agent/tcf/framework/json.c
+++ b/agent/tcf/framework/json.c
@@ -820,34 +820,43 @@ static void skip_object(InputStream * inp) {
int ch;
read_whitespace(inp);
ch = skip_char(inp);
- if (ch == 'n') {
+ switch (ch) {
+ case 'n':
check_char(skip_char(inp), 'u');
check_char(skip_char(inp), 'l');
check_char(skip_char(inp), 'l');
return;
- }
- if (ch == 'f') {
+ case 'f':
check_char(skip_char(inp), 'a');
check_char(skip_char(inp), 'l');
check_char(skip_char(inp), 's');
check_char(skip_char(inp), 'e');
return;
- }
- if (ch == 't') {
+ case 't':
check_char(skip_char(inp), 'r');
check_char(skip_char(inp), 'u');
check_char(skip_char(inp), 'e');
return;
- }
- if (ch == '"') {
+ case '"':
for (;;) {
- ch = skip_char(inp);
+ ch = read_stream(inp);
+ if (ch < 0) exception(ERR_JSON_SYNTAX);
+ buf_add(ch);
if (ch == '"') break;
if (ch == '\\') skip_char(inp);
}
return;
- }
- if (ch == '-' || (ch >= '0' && ch <= '9')) {
+ case '-':
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
for (;;) {
ch = peek_stream(inp);
if ((ch < '0' || ch > '9') && ch != '.'
@@ -855,8 +864,7 @@ static void skip_object(InputStream * inp) {
skip_char(inp);
}
return;
- }
- if (ch == '[') {
+ case '[':
if (json_peek(inp) == ']') {
skip_char(inp);
}
@@ -872,14 +880,12 @@ static void skip_object(InputStream * inp) {
}
}
return;
- }
- if (ch == '{') {
+ case '{':
if (json_peek(inp) == '}') {
skip_char(inp);
}
else {
for (;;) {
- int ch;
skip_object(inp);
read_whitespace(inp);
ch = skip_char(inp);
@@ -893,18 +899,22 @@ static void skip_object(InputStream * inp) {
}
}
return;
- }
- if (ch == '(') {
- unsigned long size = json_read_ulong(inp);
- ch = skip_char(inp);
- check_char(ch, ')');
- while (size) {
- skip_char(inp);
- size--;
+ case '(':
+ {
+ unsigned long size = json_read_ulong(inp);
+ ch = skip_char(inp);
+ check_char(ch, ')');
+ while (size) {
+ ch = read_stream(inp);
+ if (ch < 0) exception(ERR_JSON_SYNTAX);
+ buf_add(ch);
+ size--;
+ }
}
return;
+ default:
+ exception(ERR_JSON_SYNTAX);
}
- exception(ERR_JSON_SYNTAX);
}
char * json_read_object(InputStream * inp) {
diff --git a/agent/tcf/framework/protocol.c b/agent/tcf/framework/protocol.c
index 3e1228aa..f1e72851 100644
--- a/agent/tcf/framework/protocol.c
+++ b/agent/tcf/framework/protocol.c
@@ -97,8 +97,8 @@ static void read_stringz(InputStream * inp, char * str, size_t size) {
unsigned len = 0;
for (;;) {
int ch = read_stream(inp);
- if (ch == 0) break;
- if (ch < 0) {
+ if (ch <= 0) {
+ if (ch == 0) break;
trace(LOG_ALWAYS, "Unexpected end of message");
exception(ERR_PROTOCOL);
}

Back to the top