From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [PATCH]: Add new bytecode op `switch' for implementing branch tables. Date: Thu, 09 Feb 2017 08:21:21 -0500 Message-ID: References: <1b07c68a-873e-83c8-246d-423bc83a3881@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1486646904 15730 195.159.176.226 (9 Feb 2017 13:28:24 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 9 Feb 2017 13:28:24 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: =?windows-1252?Q?Cl=E9ment?= Pit-Claudel , "emacs-devel@gnu.org" To: Vibhav Pant Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Feb 09 14:28:17 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cbolk-0003h2-7e for ged-emacs-devel@m.gmane.org; Thu, 09 Feb 2017 14:28:16 +0100 Original-Received: from localhost ([::1]:37921 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cbolp-0005kH-T4 for ged-emacs-devel@m.gmane.org; Thu, 09 Feb 2017 08:28:21 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39136) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cbofg-0000Xc-DH for emacs-devel@gnu.org; Thu, 09 Feb 2017 08:22:01 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cbofb-0001Bs-Fp for emacs-devel@gnu.org; Thu, 09 Feb 2017 08:22:00 -0500 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:55786) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cbofb-0001BG-8q for emacs-devel@gnu.org; Thu, 09 Feb 2017 08:21:55 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0DsBAAu3EVY//7rSC1dGgEBAQECAQEBAQgBAQEBgzgBAQEBAR+EW6FWJgGSR4IPggiGHAQCAoIRQRMBAgEBAQEBAQFiKIRpAQQBJy8jBQsLNBIUGA0kiHoIrFc9i0QBAQgCJYsZiikFj3yKaoxthjOHeoY6kg8hAjN4Ew6DWx2BeyCJLQEBAQ X-IPAS-Result: A0DsBAAu3EVY//7rSC1dGgEBAQECAQEBAQgBAQEBgzgBAQEBAR+EW6FWJgGSR4IPggiGHAQCAoIRQRMBAgEBAQEBAQFiKIRpAQQBJy8jBQsLNBIUGA0kiHoIrFc9i0QBAQgCJYsZiikFj3yKaoxthjOHeoY6kg8hAjN4Ew6DWx2BeyCJLQEBAQ X-IronPort-AV: E=Sophos;i="5.33,749,1477972800"; d="scan'208";a="292459543" Original-Received: from 45-72-235-254.cpe.teksavvy.com (HELO pastel.home) ([45.72.235.254]) by smtp.teksavvy.com with ESMTP; 09 Feb 2017 08:21:22 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id A91B863FB6; Thu, 9 Feb 2017 08:21:21 -0500 (EST) In-Reply-To: (Vibhav Pant's message of "Wed, 8 Feb 2017 21:51:23 +0530") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:212165 Archived-At: >> + if (HASH_TABLE_SIZE (h) <= 5 && h->test.cmpfn) { Why not use the linear search when h->test.cmpfn is NULL (i.e. for `eq` hash tables)? >> + /*Try doing a linear search first */ Nitpick: this should be /* Try doing a linear search first. */ Notice the space at the beginning and the double space after the end of sentence. >> + ptrdiff_t i; >> + for (i = 0; i < HASH_TABLE_SIZE (h); i++) >> + { >> + if (h->test.cmpfn (&h->test, key, HASH_KEY (h, i))) >> + return i; >> + } >> + return -1; >> + } I think we should check hash_code before calling cmpfn. > Looks like this is the incorrect way to linear-search a hash table, as > it's sometimes resulting in duplicate hash table entries. Maybe because it fails to set *hash ? Stefan