Optimization here and there, changes because of PJLIB modifications

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@74 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/src/pjsip-simple/event_notify.c b/pjsip/src/pjsip-simple/event_notify.c
index 25869c4..51fe769 100644
--- a/pjsip/src/pjsip-simple/event_notify.c
+++ b/pjsip/src/pjsip-simple/event_notify.c
@@ -336,7 +336,7 @@
 	pj_mutex_unlock( mgr.mutex );
 
     }
-    PJ_DEFAULT {
+    PJ_CATCH_ANY {
 	PJ_LOG(4,(THIS_FILE, "event_sub%p (%s): caught exception %d during init", 
 			     sub, state[sub->state].ptr, PJ_GET_EXCEPTION()));
 
diff --git a/pjsip/src/pjsip-ua/sip_dialog.c b/pjsip/src/pjsip-ua/sip_dialog.c
index bb4861b..542b3f4 100644
--- a/pjsip/src/pjsip-ua/sip_dialog.c
+++ b/pjsip/src/pjsip-ua/sip_dialog.c
@@ -756,7 +756,7 @@
 	dlg_create_request_throw(&tdata, dlg, method, cseq);
 	PJ_LOG(5, (dlg->obj_name, "request data %s created", tdata->obj_name));
     }
-    PJ_DEFAULT {
+    PJ_CATCH_ANY {
 	/* Failed! Delete transmit data. */
 	if (tdata) {
 	    pjsip_tx_data_dec_ref( tdata );
diff --git a/pjsip/src/pjsip/sip_parser.c b/pjsip/src/pjsip/sip_parser.c
index 4af7a63..248f0b7 100644
--- a/pjsip/src/pjsip/sip_parser.c
+++ b/pjsip/src/pjsip/sip_parser.c
@@ -183,7 +183,7 @@
 }
 
 /* Case insensitive comparison */
-#define parser_stricmp(str1, str2)  pj_stricmp(&str1, &str2)
+#define parser_stricmp(s1, s2)  (pj_stricmp_alnum(&s1, &s2))
 
 
 /* Syntax error handler for parser. */
@@ -551,7 +551,7 @@
     PJ_TRY {
 	msg = int_parse_msg(&context, err_list);
     } 
-    PJ_DEFAULT {
+    PJ_CATCH_ANY {
 	msg = NULL;
     }
     PJ_END
@@ -580,7 +580,7 @@
     PJ_TRY {
 	rdata->msg_info.msg = int_parse_msg(&context, &rdata->msg_info.parse_err);
     } 
-    PJ_DEFAULT {
+    PJ_CATCH_ANY {
 	rdata->msg_info.msg = NULL;
     }
     PJ_END
@@ -656,7 +656,10 @@
 
 		/* Found a valid Content-Length header. */
 		content_length = pj_strtoul(&str_clen);
-	    } 
+	    }
+	    PJ_CATCH_ANY {
+		content_length = -1;
+	    }
 	    PJ_END
 
 	    pj_scan_fini(&scanner);
@@ -691,9 +694,9 @@
 					 char *buf, pj_size_t size,
 					 unsigned option)
 {
-    PJ_USE_EXCEPTION;
     pj_scanner scanner;
     pjsip_uri *uri = NULL;
+    PJ_USE_EXCEPTION;
 
     init_sip_parser();
 
@@ -703,6 +706,9 @@
     PJ_TRY {
 	uri = int_parse_uri_or_name_addr(&scanner, pool, option);
     }
+    PJ_CATCH_ANY {
+	uri = NULL;
+    }
     PJ_END;
 
     /* Must have exhausted all inputs. */
@@ -738,12 +744,12 @@
 static pjsip_msg *int_parse_msg( pjsip_parse_ctx *ctx,
 				 pjsip_parser_err_report *err_list)
 {
-    PJ_USE_EXCEPTION;
     int ch;
     pjsip_msg *msg;
     pjsip_ctype_hdr *ctype_hdr = NULL;
     pj_scanner *scanner = ctx->scanner;
     pj_pool_t *pool = ctx->pool;
+    PJ_USE_EXCEPTION;
 
     /* Skip leading newlines. */
     ch = *scanner->curptr;
@@ -800,7 +806,7 @@
 	    }
 
 	}
-	PJ_DEFAULT {
+	PJ_CATCH_ANY {
 	    /* Exception was thrown during parsing. 
 	     * Skip until newline, and parse next header. 
 	     */
@@ -815,7 +821,7 @@
 		pjsip_parser_err_report *err_info;
 		
 		err_info = pj_pool_alloc(pool, sizeof(*err_info));
-		err_info->exception_code = PJ_GET_EXCEPTION();
+		err_info->except_code = PJ_GET_EXCEPTION();
 		err_info->line = scanner->line;
 		err_info->col = scanner->col;
 		err_info->hname = hname;
@@ -1079,10 +1085,9 @@
 				     pj_bool_t parse_params)
 {
     pj_str_t scheme;
-    pjsip_url *url;
+    pjsip_url *url = NULL;
     int colon;
     int skip_ws = scanner->skip_ws;
-    int hsep = '?';
     scanner->skip_ws = 0;
 
     pj_scan_get(scanner, &pjsip_TOKEN_SPEC, &scheme);
@@ -1114,7 +1119,8 @@
     int_parse_uri_host_port(scanner, &url->host, &url->port);
 
     /* Get URL parameters. */
-    while ( parse_params && *scanner->curptr == ';' ) {
+    if (parse_params) {
+      while (*scanner->curptr == ';' ) {
 	pj_str_t pname, pvalue;
 
 	int_parse_param( scanner, pool, &pname, &pvalue);
@@ -1143,15 +1149,17 @@
 	    p->value = pvalue;
 	    pj_list_insert_before(&url->other_param, p);
 	}
+      }
     }
 
     /* Get header params. */
-    while (parse_params && *scanner->curptr == hsep) {
+    if (parse_params && *scanner->curptr == '?') {
+      do {
 	pjsip_param *param;
 	param = pj_pool_alloc(pool, sizeof(pjsip_param));
 	int_parse_hparam(scanner, pool, &param->name, &param->value);
 	pj_list_insert_before(&url->header_param, param);
-	hsep = '&';
+      } while (*scanner->curptr == '&');
     }
 
     scanner->skip_ws = skip_ws;
@@ -1774,7 +1782,7 @@
 	}
 
     } 
-    PJ_DEFAULT {
+    PJ_CATCH_ANY {
 	hdr = NULL;
     }
     PJ_END
diff --git a/pjsip/src/pjsip/sip_uri.c b/pjsip/src/pjsip/sip_uri.c
index ab25880..a446425 100644
--- a/pjsip/src/pjsip/sip_uri.c
+++ b/pjsip/src/pjsip/sip_uri.c
@@ -46,7 +46,7 @@
 {
     const pjsip_param *p = param_list->next;
     while (p != param_list) {
-	if (pj_stricmp(&p->name, name)==0)
+	if (pj_stricmp_alnum(&p->name, name)==0)
 	    return p;
 	p = p->next;
     }
diff --git a/pjsip/src/pjsip/sip_util.c b/pjsip/src/pjsip/sip_util.c
index 4531117..57ef6fb 100644
--- a/pjsip/src/pjsip/sip_util.c
+++ b/pjsip/src/pjsip/sip_util.c
@@ -322,7 +322,7 @@
 	init_request_throw( endpt, tdata, &cseq->method, target, from, to, 
                             contact, call_id, cseq, param_text);
     }
-    PJ_DEFAULT {
+    PJ_CATCH_ANY {
 	status = PJ_ENOMEM;
 	goto on_error;
     }
@@ -393,7 +393,7 @@
 	init_request_throw(endpt, tdata, &cseq->method, target, from, to, 
                            contact, call_id, cseq, param_text);
     }
-    PJ_DEFAULT {
+    PJ_CATCH_ANY {
 	status = PJ_ENOMEM;
 	goto on_error;
     }
diff --git a/pjsip/src/test-pjsip/uri.c b/pjsip/src/test-pjsip/uri.c
index 4435d1a..7afcbbe 100644
--- a/pjsip/src/test-pjsip/uri.c
+++ b/pjsip/src/test-pjsip/uri.c
@@ -29,13 +29,13 @@
 #define PASS_CHAR   ALPHANUM MARK "&=+$,"
 #define PARAM_CHAR  ALPHANUM MARK "[]/:&+$"
 
-#define POOL_SIZE	4000
-#define LOOP_COUNT	1000
+#define POOL_SIZE	8000
+#define LOOP_COUNT	10000
 #define AVERAGE_URL_LEN	80
 #define THREAD_COUNT	4
 
-static pj_uint32_t parse_len;
-static pj_timestamp parse_time, print_time;
+static pj_highprec_t parse_len, print_len, cmp_len;
+static pj_timestamp parse_time, print_time, cmp_time;
 
 
 /* URI creator functions. */
@@ -83,8 +83,7 @@
     {
 	PJ_SUCCESS,
 	"sip:user:password@localhost:5060",
-	&create_uri2,
-    },
+	&create_uri2,    },
     {
 	/* Port is specified should not match unspecified port. */
 	ERR_NOT_EQUAL,
@@ -498,7 +497,7 @@
 
     /* Parse URI text. */
     pj_get_timestamp(&t1);
-    parse_len += entry->len;
+    parse_len = parse_len + entry->len;
     parsed_uri = pjsip_parse_uri(pool, entry->str, entry->len, 0);
     if (!parsed_uri) {
 	/* Parsing failed. If the entry says that this is expected, then
@@ -532,6 +531,7 @@
     s1.ptr[len] = '\0';
     s1.slen = len;
 
+    print_len = print_len + len;
     pj_get_timestamp(&t2);
     pj_sub_timestamp(&t2, &t1);
     pj_add_timestamp(&print_time, &t2);
@@ -545,6 +545,7 @@
     s2.slen = len;
 
     /* Full comparison of parsed URI with reference URI. */
+    pj_get_timestamp(&t1);
     status = pjsip_uri_cmp(PJSIP_URI_IN_OTHER, parsed_uri, ref_uri);
     if (status != 0) {
 	/* Not equal. See if this is the expected status. */
@@ -565,6 +566,11 @@
 	}
     }
 
+    cmp_len = cmp_len + len;
+    pj_get_timestamp(&t2);
+    pj_sub_timestamp(&t2, &t1);
+    pj_add_timestamp(&cmp_time, &t2);
+
     /* Compare text. */
     if (pj_strcmp(&s1, &s2) != 0) {
 	/* Not equal. */
@@ -581,7 +587,8 @@
     pj_pool_t *pool;
     pj_status_t status;
     pj_timestamp zero;
-    pj_highprec_t avg_parse, avg_print;
+    pj_time_val elapsed;
+    pj_highprec_t avg_parse, avg_print, avg_cmp, kbytes;
 
     zero.u32.hi = zero.u32.lo = 0;
 
@@ -598,39 +605,70 @@
     pjsip_endpt_destroy_pool(endpt, pool);
 
     PJ_LOG(3,("", "  benchmarking..."));
-    parse_len = 0;
+    parse_len = print_len = cmp_len = 0;
     parse_time.u32.hi = parse_time.u32.lo = 0;
     print_time.u32.hi = print_time.u32.lo = 0;
-    pool = pjsip_endpt_create_pool(endpt, "", POOL_SIZE, POOL_SIZE);
+    cmp_time.u32.hi = cmp_time.u32.lo = 0;
     for (loop=0; loop<LOOP_COUNT; ++loop) {
+	pool = pjsip_endpt_create_pool(endpt, "", POOL_SIZE, POOL_SIZE);
 	for (i=0; i<PJ_ARRAY_SIZE(uri_test_array); ++i) {
 	    status = do_uri_test(pool, &uri_test_array[i]);
 	    if (status != PJ_SUCCESS) {
 		PJ_LOG(3,("uri_test", "  error %d when testing entry %d",
 			  status, i));
+		pjsip_endpt_destroy_pool(endpt, pool);
 		goto on_return;
 	    }
 	}
+	pjsip_endpt_destroy_pool(endpt, pool);
     }
 
+    kbytes = parse_len;
+    pj_highprec_mod(kbytes, 1000000);
+    pj_highprec_div(kbytes, 100000);
+    elapsed = pj_elapsed_time(&zero, &parse_time);
     avg_parse = pj_elapsed_usec(&zero, &parse_time);
     pj_highprec_mul(avg_parse, AVERAGE_URL_LEN);
     pj_highprec_div(avg_parse, parse_len);
     avg_parse = 1000000 / avg_parse;
 
+    PJ_LOG(3,("", "    %u.%u MB of urls parsed in %d.%03ds (avg=%d urls/sec)", 
+		  (unsigned)(parse_len/1000000), (unsigned)kbytes,
+		  elapsed.sec, elapsed.msec,
+		  (unsigned)avg_parse));
+
+    kbytes = print_len;
+    pj_highprec_mod(kbytes, 1000000);
+    pj_highprec_div(kbytes, 100000);
+    elapsed = pj_elapsed_time(&zero, &print_time);
     avg_print = pj_elapsed_usec(&zero, &print_time);
     pj_highprec_mul(avg_print, AVERAGE_URL_LEN);
     pj_highprec_div(avg_print, parse_len);
     avg_print = 1000000 / avg_print;
 
-    PJ_LOG(3,("", "   done. Average parse=%d url/sec, print=%d url/sec",
-		  (unsigned)avg_parse, (unsigned)avg_print));
+    PJ_LOG(3,("", "    %u.%u MB of urls printed in %d.%03ds (avg=%d urls/sec)", 
+		  (unsigned)(print_len/1000000), (unsigned)kbytes,
+		  elapsed.sec, elapsed.msec,
+		  (unsigned)avg_print));
+
+    kbytes = cmp_len;
+    pj_highprec_mod(kbytes, 1000000);
+    pj_highprec_div(kbytes, 100000);
+    elapsed = pj_elapsed_time(&zero, &cmp_time);
+    avg_cmp = pj_elapsed_usec(&zero, &cmp_time);
+    pj_highprec_mul(avg_cmp, AVERAGE_URL_LEN);
+    pj_highprec_div(avg_cmp, cmp_len);
+    avg_cmp = 1000000 / avg_cmp;
+
+    PJ_LOG(3,("", "    %u.%u MB of urls compared in %d.%03ds (avg=%d urls/sec)", 
+		  (unsigned)(cmp_len/1000000), (unsigned)kbytes,
+		  elapsed.sec, elapsed.msec,
+		  (unsigned)avg_cmp));
 
     PJ_LOG(3,("", "  multithreaded test"));
 
 
 on_return:
-    pjsip_endpt_destroy_pool(endpt, pool);
     return status;
 }