[asterisk-commits] russell: branch russell/event_performance r183649 - in /team/russell/event_pe...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Mar 22 14:08:50 CDT 2009


Author: russell
Date: Sun Mar 22 14:08:46 2009
New Revision: 183649

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=183649
Log:
Speed up cache processing by storing a hash in front of a string payload to avoid
more expensive string comparisons.

Modified:
    team/russell/event_performance/include/asterisk/event.h
    team/russell/event_performance/main/event.c

Modified: team/russell/event_performance/include/asterisk/event.h
URL: http://svn.digium.com/svn-view/asterisk/team/russell/event_performance/include/asterisk/event.h?view=diff&rev=183649&r1=183648&r2=183649
==============================================================================
--- team/russell/event_performance/include/asterisk/event.h (original)
+++ team/russell/event_performance/include/asterisk/event.h Sun Mar 22 14:08:46 2009
@@ -511,6 +511,18 @@
 const char *ast_event_get_ie_str(const struct ast_event *event, enum ast_event_ie_type ie_type);
 
 /*!
+ * \brief Get the hash for the string payload of an IE
+ *
+ * \param event The event to get the IE from
+ * \param ie_type the type of information element to retrieve the hash for
+ *
+ * \return This function returns the hash value as calculated by ast_str_hash()
+ *         for the string payload.  This is stored in the event to avoid
+ *         unnecessary string comparisons.
+ */
+uint32_t ast_event_get_ie_str_hash(const struct ast_event *event, enum ast_event_ie_type ie_type);
+
+/*!
  * \brief Get the value of an information element that has a raw payload
  *
  * \param event The event to get the IE from

Modified: team/russell/event_performance/main/event.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/event_performance/main/event.c?view=diff&rev=183649&r1=183648&r2=183649
==============================================================================
--- team/russell/event_performance/main/event.c (original)
+++ team/russell/event_performance/main/event.c Sun Mar 22 14:08:46 2009
@@ -52,6 +52,11 @@
 	/*! Total length of the IE payload */
 	uint16_t ie_payload_len;
 	unsigned char ie_payload[0];
+} __attribute__((packed));
+
+struct ast_event_ie_str_payload {
+	uint32_t hash;
+	char str[1];
 } __attribute__((packed));
 
 /*!
@@ -85,7 +90,10 @@
 	enum ast_event_ie_pltype ie_pltype;
 	union {
 		uint32_t uint;
-		const char *str;
+		struct {
+			uint32_t hash;
+			const char *str;
+		};
 		void *raw;
 	} payload;
 	size_t raw_datalen;
@@ -338,9 +346,19 @@
 	}
 
 	if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_STR) {
-		const char *str = event2 ? ast_event_get_ie_str(event2, ie_val->ie_type) : ie_val->payload.str;
-		if (str && !strcmp(str, ast_event_get_ie_str(event, ie_val->ie_type)))
+		const char *str;
+		uint32_t hash;
+
+		hash = event2 ? ast_event_get_ie_str_hash(event2, ie_val->ie_type) : ie_val->payload.hash;
+		if (hash != ast_event_get_ie_str_hash(event, ie_val->ie_type)) {
+			return 0;
+		}
+
+		str = event2 ? ast_event_get_ie_str(event2, ie_val->ie_type) : ie_val->payload.str;
+		if (str && !strcmp(str, ast_event_get_ie_str(event, ie_val->ie_type))) {
 			return 1;
+		}
+
 		return 0;
 	}
 
@@ -535,6 +553,8 @@
 		ast_free(ie_val);
 		return -1;
 	}
+
+	ie_val->payload.hash = ast_str_hash(str);
 
 	AST_LIST_INSERT_TAIL(&sub->ie_vals, ie_val, entry);
 
@@ -703,7 +723,11 @@
 
 const char *ast_event_iterator_get_ie_str(struct ast_event_iterator *iterator)
 {
-	return (const char*)iterator->ie->ie_payload;
+	const struct ast_event_ie_str_payload *str_payload;
+
+	str_payload = (struct ast_event_ie_str_payload *) iterator->ie->ie_payload;
+
+	return str_payload->str;
 }
 
 void *ast_event_iterator_get_ie_raw(struct ast_event_iterator *iterator)
@@ -725,9 +749,22 @@
 	return ie_val ? ntohl(get_unaligned_uint32(ie_val)) : 0;
 }
 
+uint32_t ast_event_get_ie_str_hash(const struct ast_event *event, enum ast_event_ie_type ie_type)
+{
+	const struct ast_event_ie_str_payload *str_payload;
+
+	str_payload = ast_event_get_ie_raw(event, ie_type);
+
+	return str_payload->hash;
+}
+
 const char *ast_event_get_ie_str(const struct ast_event *event, enum ast_event_ie_type ie_type)
 {
-	return ast_event_get_ie_raw(event, ie_type);
+	const struct ast_event_ie_str_payload *str_payload;
+
+	str_payload = ast_event_get_ie_raw(event, ie_type);
+
+	return str_payload->str;
 }
 
 const void *ast_event_get_ie_raw(const struct ast_event *event, enum ast_event_ie_type ie_type)
@@ -746,7 +783,16 @@
 int ast_event_append_ie_str(struct ast_event **event, enum ast_event_ie_type ie_type,
 	const char *str)
 {
-	return ast_event_append_ie_raw(event, ie_type, str, strlen(str) + 1);
+	struct ast_event_ie_str_payload *str_payload;
+	size_t payload_len;
+
+	payload_len = sizeof(*str_payload) + strlen(str);
+	str_payload = alloca(payload_len);
+
+	strcpy(str_payload->str, str);
+	str_payload->hash = ast_str_hash(str);
+
+	return ast_event_append_ie_raw(event, ie_type, str_payload, payload_len);
 }
 
 int ast_event_append_ie_uint(struct ast_event **event, enum ast_event_ie_type ie_type,




More information about the asterisk-commits mailing list