From efa9e4e5c212368e75e3602eef9aa1f50cd9bf18 Mon Sep 17 00:00:00 2001
From: Per Hedbor <ph@opera.com>
Date: Mon, 23 Feb 2015 13:33:44 +0100
Subject: [PATCH] encode_value: Slightly faster encode of large integers.

Also, do not remember items with only 1 reference, they are rather
unlikely to show up again later on (objects notwithstanding, and they
are handled in another case).

This saves a lot of CPU time when a large array of fairly unique
strings are encoded.
---
 src/encode.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/encode.c b/src/encode.c
index c1f8134ac9..8215406e89 100644
--- a/src/encode.c
+++ b/src/encode.c
@@ -516,7 +516,6 @@ static void encode_value2(struct svalue *val, struct encode_data *data, int forc
 	    fprintf(stderr,"TAG%d", TYPEOF(*val));
 	  }else{
 	    print_svalue(stderr, val);
-	  
 	  }
 	  fputc('\n', stderr););
       code_entry (TAG_DELAYED, entry_id.u.integer, data);
@@ -541,10 +540,11 @@ static void encode_value2(struct svalue *val, struct encode_data *data, int forc
 	  {
 	    fprintf(stderr,"TAG%d", TYPEOF(*val));
 	  }else{
-	    print_svalue(stderr, val);	  
+	    print_svalue(stderr, val);
 	  }
 	  fputc('\n', stderr););
-      mapping_insert(data->encoded, val, &entry_id);
+      if( TYPEOF(*val) < MIN_REF_TYPE || val->u.dummy->refs > 1 )
+          mapping_insert(data->encoded, val, &entry_id);
       data->counter.u.integer++;
     }
   }
-- 
GitLab