php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #52832
Patch php-5.3-unserialize-performance.patch revision 2010-09-14 16:32 UTC by galaxy dot mipt at gmail dot com

Patch php-5.3-unserialize-performance.patch for Performance problem Bug #52832

Patch version 2010-09-14 16:32 UTC

Return to Bug #52832 | Download this patch
Patch Revisions:

Developer: galaxy.mipt@gmail.com

Index: ext/standard/php_var.h
===================================================================
--- ext/standard/php_var.h	(revision 303366)
+++ ext/standard/php_var.h	(working copy)
@@ -42,7 +42,9 @@
 
 struct php_unserialize_data {
 	void *first;
+	void *last;
 	void *first_dtor;
+	void *last_dtor;
 };
 
 typedef struct php_unserialize_data php_unserialize_data_t;
@@ -57,7 +59,9 @@
 
 #define PHP_VAR_UNSERIALIZE_INIT(var_hash) \
 	(var_hash).first = 0; \
-	(var_hash).first_dtor = 0
+	(var_hash).last = 0; \
+	(var_hash).first_dtor = 0; \
+	(var_hash).last_dtor = 0
 #define PHP_VAR_UNSERIALIZE_DESTROY(var_hash) \
 	var_destroy(&(var_hash))
 
Index: ext/standard/var_unserializer.re
===================================================================
--- ext/standard/var_unserializer.re	(revision 303366)
+++ ext/standard/var_unserializer.re	(working copy)
@@ -33,14 +33,9 @@
 
 static inline void var_push(php_unserialize_data_t *var_hashx, zval **rval)
 {
-	var_entries *var_hash = var_hashx->first, *prev = NULL;
+	var_entries *var_hash = var_hashx->last;
 
-	while (var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) {
-		prev = var_hash;
-		var_hash = var_hash->next;
-	}
-
-	if (!var_hash) {
+	if (!var_hash || var_hash->used_slots == VAR_ENTRIES_MAX) {
 		var_hash = emalloc(sizeof(var_entries));
 		var_hash->used_slots = 0;
 		var_hash->next = 0;
@@ -48,7 +43,9 @@
 		if (!var_hashx->first)
 			var_hashx->first = var_hash;
 		else
-			prev->next = var_hash;
+			((var_entries *) var_hashx->last)->next = var_hash;
+
+		var_hashx->last = var_hash;
 	}
 
 	var_hash->data[var_hash->used_slots++] = *rval;
@@ -56,14 +53,9 @@
 
 PHPAPI void var_push_dtor(php_unserialize_data_t *var_hashx, zval **rval)
 {
-	var_entries *var_hash = var_hashx->first_dtor, *prev = NULL;
+	var_entries *var_hash = var_hashx->last_dtor;
 
-	while (var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) {
-		prev = var_hash;
-		var_hash = var_hash->next;
-	}
-
-	if (!var_hash) {
+	if (!var_hash || var_hash->used_slots == VAR_ENTRIES_MAX) {
 		var_hash = emalloc(sizeof(var_entries));
 		var_hash->used_slots = 0;
 		var_hash->next = 0;
@@ -71,7 +63,9 @@
 		if (!var_hashx->first_dtor)
 			var_hashx->first_dtor = var_hash;
 		else
-			prev->next = var_hash;
+			((var_entries *) var_hashx->last_dtor)->next = var_hash;
+
+		var_hashx->last_dtor = var_hash;
 	}
 
 	Z_ADDREF_PP(rval);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 23:01:29 2024 UTC