From 5f775cae00a9fe467d5fcad09be8b9a5503bf8f0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
 <grubba@grubba.org>
Date: Wed, 3 Sep 2014 17:10:13 +0200
Subject: [PATCH] encode_value: Simplify the handling of the variant
 dispatcher.

Removed special case code in two places that compensated for each other.
---
 src/encode.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/encode.c b/src/encode.c
index aad9889422..2b1d313df4 100644
--- a/src/encode.c
+++ b/src/encode.c
@@ -1385,8 +1385,7 @@ static void encode_value2(struct svalue *val, struct encode_data *data, int forc
 			       "is inherited.\n", id->name);
 		  }
 		  gs_flags = ref->id_flags & PTR_FROM_INT(p, i)->id_flags;
-		  if (id_dumped[PTR_FROM_INT(p, i)->identifier_offset] ||
-		      (i < d)) {
+		  if (id_dumped[PTR_FROM_INT(p, i)->identifier_offset]) {
 		    /* Either already dumped, or the dispatcher is in
 		     * front of us, which indicates that we are overloading
 		     * an inherited function with a variant.
@@ -1535,9 +1534,14 @@ static void encode_value2(struct svalue *val, struct encode_data *data, int forc
 		     *     for it gets set by the variant functions,
 		     *     if it is overriding an old definition.
 		     *
-		     * We thus need to make sure id_dumped stays cleared.
+		     * Note that this means that even the first local
+		     * function must have the variant modifier (since
+		     * otherwise it would have overridden the old def
+		     * and not the dispatcher). This is handled
+		     * automatically by the use of id_dumped for the
+		     * dispatcher as marker for whether the first
+		     * variant has been added or not.
 		     */
-		    id_dumped[ref->identifier_offset] = 0;
 		    continue;
 		  }
 		  /* Not supported. */
-- 
GitLab