Explorar o código

htable: map $shtrecord() inner names over integer ids

- avoid string comparison at runtime
Daniel-Constantin Mierla %!s(int64=8) %!d(string=hai) anos
pai
achega
8ce1bcd52c
Modificáronse 1 ficheiros con 35 adicións e 27 borrados
  1. 35 27
      src/modules/htable/ht_var.c

+ 35 - 27
src/modules/htable/ht_var.c

@@ -368,49 +368,57 @@ int pv_get_ht_dec(struct sip_msg *msg,  pv_param_t *param,
 
 int pv_parse_ht_expired_cell(pv_spec_t *sp, str *in)
 {
-	if ((in->len != 3 || strncmp(in->s, "key", in->len) != 0) &&
-			(in->len != 5 || strncmp(in->s, "value", in->len) != 0))
-	{
+	if(sp==NULL || in==NULL || in->len<=0)
 		return -1;
+	switch(in->len)
+	{
+		case 3:
+			if(strncmp(in->s, "key", in->len)==0) {
+				sp->pvp.pvn.u.isname.name.n = 0;
+			} else {
+				goto error;
+			}
+		break;
+		case 5:
+			if(strncmp(in->s, "value", in->len)==0) {
+				sp->pvp.pvn.u.isname.name.n = 1;
+			} else {
+				goto error;
+			}
+		break;
+		default:
+			goto error;
 	}
-
-	sp->pvp.pvn.u.isname.name.s.s = in->s;
-	sp->pvp.pvn.u.isname.name.s.len = in->len;
 	sp->pvp.pvn.u.isname.type = 0;
 	sp->pvp.pvn.type = PV_NAME_INTSTR;
 
 	return 0;
+
+error:
+	LM_ERR("unknown pv name %.*s\n", in->len, in->s);
+	return -1;
 }
 
 int pv_get_ht_expired_cell(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res)
 {
-	if (res == NULL || ht_expired_cell == NULL)
-	{
+	if (res == NULL || ht_expired_cell == NULL) {
 		return -1;
 	}
 
-	if (param->pvn.u.isname.name.s.len == 3 &&
-		strncmp(param->pvn.u.isname.name.s.s, "key", 3) == 0)
-	{
-		res->rs = ht_expired_cell->name;
-	}
-	else if (param->pvn.u.isname.name.s.len == 5 &&
-		strncmp(param->pvn.u.isname.name.s.s, "value", 5) == 0)
+	switch(param->pvn.u.isname.name.n)
 	{
-		if(ht_expired_cell->flags&AVP_VAL_STR) {
-			return pv_get_strval(msg, param, res, &ht_expired_cell->value.s);
-		} else {
-			return pv_get_sintval(msg, param, res, ht_expired_cell->value.n);
-		}
+		case 0:
+			return pv_get_strval(msg, param, res, &ht_expired_cell->name);
+		case 1:
+			if(ht_expired_cell->flags&AVP_VAL_STR) {
+				return pv_get_strval(msg, param, res, &ht_expired_cell->value.s);
+			} else {
+				return pv_get_sintval(msg, param, res, ht_expired_cell->value.n);
+			}
+		default:
+			return pv_get_null(msg, param, res);
 	}
-
-	if (res->rs.s == NULL)
-		res->flags = PV_VAL_NULL;
-	else
-		res->flags = PV_VAL_STR;
-
-	return 0;
 }
 
 int pv_parse_iterator_name(pv_spec_t *sp, str *in)