From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tim Deegan Subject: Re: [PATCH 10/17] vmx: nest: VMExit handler in L2 Date: Tue, 25 May 2010 16:34:51 +0100 Message-ID: <20100525153451.GC15976@whitby.uk.xensource.com> References: <1271929289-18572-1-git-send-email-qing.he@intel.com> <1271929289-18572-11-git-send-email-qing.he@intel.com> <20100520114414.GQ4164@whitby.uk.xensource.com> <20100520160606.GD21538@qhe2-db> <20100521084215.GV4164@whitby.uk.xensource.com> <20100521103523.GD21018@qhe2-db> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Return-path: Content-Disposition: inline In-Reply-To: <20100521103523.GD21018@qhe2-db> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Qing He Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org At 11:35 +0100 on 21 May (1274441723), Qing He wrote: > > I understand that. It just seems inefficient to bundle them all > > together into one clause of the switch statement and then scan an array > > looking for which one you've hit. Wouldn't it be better to give each > > one its own clause and then use goto (!) or similar to jump to the > > common code? > > Ok, I'll change it to switch clauses, does it mean to be more friendly to > the compiler? No, it's just faster; I don't think GCC can optimize out a while loop, even scanning a static array with a known limited set of possible inputs (though i would be delighted to hear otherwise). Just to be clear, I'm talking about replacing this kind of logic switch (x) { case a: case b: case c: for (i = o; i < 3 ; i++) if ( x == array[i] ) /* do case-specific thing */ /* do common case */ } with this equivalent: switch (x) { case a: /* do a-specific thing */ goto common; case b: /* do b-specific thing */ goto common; case c: /* do c-specific thing */ goto common; common: /* do common case */ } Cheers, Tim. -- Tim Deegan Principal Software Engineer, XenServer Engineering Citrix Systems UK Ltd. (Company #02937203, SL9 0BG)