From 58eb36fa819f715258befba1f6dc65055b779870 Mon Sep 17 00:00:00 2001
From: "Committo,Ergo:sum" <esj@rezo.net>
Date: Fri, 8 Dec 2006 07:54:40 +0000
Subject: [PATCH] =?UTF-8?q?Optimisation=20de=20la=20lecture=20d'une=20sauv?=
 =?UTF-8?q?egarde:=20pr=C3=A9venir=20syst=C3=A9matiquement=20si=20la=20zon?=
 =?UTF-8?q?e=20entre=20deux=20balises=20est=20=C3=A0=20recopier;=20=C3=A9v?=
 =?UTF-8?q?iter=20la=20copie=20interm=C3=A9diaire=20du=20buffet=20entre=20?=
 =?UTF-8?q?la=20recherche=20de=20<=20et=20celle=20de=20>=20grace=20au=203e?=
 =?UTF-8?q?=20argument=20de=20strpos.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 ecrire/inc/import.php     | 19 +++++++++++--------
 ecrire/inc/import_1_3.php | 11 +++++------
 2 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/ecrire/inc/import.php b/ecrire/inc/import.php
index 430c8e7df7..f93e95ef10 100644
--- a/ecrire/inc/import.php
+++ b/ecrire/inc/import.php
@@ -41,6 +41,7 @@ $GLOBALS['flag_ob_flush'] = function_exists('ob_flush');
 // Les balises commencant par <! sont ignorees
 // $abs_pos est globale pour pouvoir etre reinitialisee a la meta
 // status_restauration en cas d'interruption sur TimeOut.
+// Evite au maximum les recopies
 
 // http://doc.spip.org/@xml_fetch_tag
 function xml_fetch_tag($f, &$before, $_fread='fread', $skip='!') {
@@ -51,27 +52,29 @@ function xml_fetch_tag($f, &$before, $_fread='fread', $skip='!') {
 
 	while (($b=strpos($buf,'<'))===false) {
 		if (!($x = $_fread($f, 1024))) return '';
-		$buf .= $x;
+		if ($before)
+			$buf .= $x;
+		else $buf = $x;
 	}
 	if ($before) $before = str_replace($ent,$brut,substr($buf,0,$b));
 #	else { spip_log("position: $abs_pos" . substr($buf,0,12));flush();}
-	// pour ignorer un > de raccourci Spip avant un < de balise XML
 
-	$buf = substr($buf,++$b); 
+	// $b pour ignorer un > de raccourci Spip avant un < de balise XML
 
-	while (($e=strpos($buf,'>'))===false) {
+	while (($e=strpos($buf,'>', $b))===false) {
 		if (!($x = $_fread($f, 1024))) return '';
 		$buf .= $x;
 	}
-	if ($buf[0]!=$skip) {
-		$tag = substr($buf, 0, $e);
+
+	if ($buf[++$b]!=$skip) {
+		$tag = substr($buf, $b, $e-$b);
 		$buf = substr($buf,++$e);
-		$abs_pos += $e + $b;
+		$abs_pos += $e;
 		return $tag;
 	}
 
 	$buf = substr($buf,++$e);
-	$abs_pos += $e + $b;
+	$abs_pos += $e;
 	return xml_fetch_tag($f,$before,$_fread,$skip);
 }
 
diff --git a/ecrire/inc/import_1_3.php b/ecrire/inc/import_1_3.php
index b09860cf1a..01bab9ead0 100644
--- a/ecrire/inc/import_1_3.php
+++ b/ecrire/inc/import_1_3.php
@@ -127,21 +127,20 @@ function import_lire_champs($f, $fields, $gz, $phpmyadmin, $table)
 	$char = $GLOBALS['meta']['charset_insertion'];
 	if ($char == $GLOBALS['meta']['charset_restauration']) $char = '';
 
-	$b = false;
 	for (;;) {
+		$b = false;
 		if (!($col = xml_fetch_tag($f, $b, $gz))) return false;
 		if ($col[0] == '/') { 
 			if ($col != $table) {
-		    // autre tag fermant ici est une erreur de format
-			  spip_log("restauration de la table $table, tag fermant inattendu:");
-			  spip_log($col);
+				spip_log("restauration de la table $table, tag fermant inattendu:");
+				spip_log($col);
 		  }
 			break;
 		}
-		$value = true;
+		$value = $b = (($col != 'maj') AND (isset($fields[$col])));
 		if (!xml_fetch_tag($f, $value, $gz)) return false;
 
-		if ( ($col != 'maj') AND (isset($fields[$col])) ) {
+		if ($b) {
 			if ($phpmyadmin)
 				$value = str_replace($phpmyadmin[0],$phpmyadmin[1],$value);
 			if ($char) 
-- 
GitLab