From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: hash-table-{to, from}-alist Date: Tue, 02 Dec 2008 16:58:41 -0500 Message-ID: References: <863aknitfg.fsf@lifelogs.com> <86bpwe9su5.fsf@lifelogs.com> <867i6z1jo5.fsf_-_@lifelogs.com> <86ej14vhvg.fsf@lifelogs.com> <20081122054510.GA28298@tomas> <873ahkkkt5.fsf@xemacs.org> <20081122152126.GA4142@tomas> <87vdufk6do.fsf@xemacs.org> <867i6tt4yz.fsf@lifelogs.com> <87bpw4k1z6.fsf@xemacs.org> <86bpw3d829.fsf@lifelogs.com> <87k5ari5jh.fsf@xemacs.org> <86prkiiia2.fsf@lifelogs.com> <86ej0ygr5j.fsf@lifelogs.com> <861vwygpc6.fsf@lifelogs.com> <868wqzd06x.fsf@lifelogs.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1228255154 30620 80.91.229.12 (2 Dec 2008 21:59:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 2 Dec 2008 21:59:14 +0000 (UTC) Cc: emacs-devel@gnu.org To: Ted Zlatanov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Dec 02 23:00:15 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1L7dHm-0005bR-Lc for ged-emacs-devel@m.gmane.org; Tue, 02 Dec 2008 23:00:02 +0100 Original-Received: from localhost ([127.0.0.1]:46449 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L7dGc-0006zh-FO for ged-emacs-devel@m.gmane.org; Tue, 02 Dec 2008 16:58:50 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L7dGY-0006zV-RJ for emacs-devel@gnu.org; Tue, 02 Dec 2008 16:58:46 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L7dGY-0006zI-7y for emacs-devel@gnu.org; Tue, 02 Dec 2008 16:58:46 -0500 Original-Received: from [199.232.76.173] (port=44638 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L7dGY-0006zF-51 for emacs-devel@gnu.org; Tue, 02 Dec 2008 16:58:46 -0500 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:59228) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1L7dGX-0007fu-Od for emacs-devel@gnu.org; Tue, 02 Dec 2008 16:58:45 -0500 Original-Received: from alfajor.home (vpn-132-204-232-176.acd.umontreal.ca [132.204.232.176]) by chene.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id mB2Lwfv0022731; Tue, 2 Dec 2008 16:58:41 -0500 Original-Received: by alfajor.home (Postfix, from userid 20848) id 760D41C1D9; Tue, 2 Dec 2008 16:58:41 -0500 (EST) In-Reply-To: <868wqzd06x.fsf@lifelogs.com> (Ted Zlatanov's message of "Mon, 01 Dec 2008 16:01:42 -0600") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV3160=0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:106439 Archived-At: > + /* will this be freed automatically? */ > + Lisp_Object* params = (Lisp_Object*) xmalloc (10 * sizeof(Lisp_Object)); No, it won't be freed automatically. Why not use `alloca' instead? Also rather than 10, why not use something like XINT (Flength (tmp)) ? > + if (!EQ (head, Qhash_table_read_marker)) This constant should be called Qhash_table. > + while (!NILP(tmp)) > + { > + tmp = CDR_SAFE(tmp); > + head = CAR_SAFE(tmp); If you replace !NILP with CONSP, you can replace CDR_SAFE with XCDR (which is more efficient since it presumes you've done the CONSP test earlier). > + /* allowed parameters: size test weakness > + rehash-size rehash-threshold */ Why not :weakness, :rehash-size, :rehash-threshold? (maybe even :test and :size, although IIUC we may prefer just `size' and `test' for compatibility with XEmacs, tho I'm not sure how important that is for this kind of data). > + if (EQ(head, Qhash_table_data_marker)) It should just be called Qdata. Also you need to put spaces before all your open parens. > + { > + tmp = CDR_SAFE(tmp); > + data = CAR_SAFE(tmp); > + /* debug_print(data); */ > + } > + > + if ( > + param_count < 9 && > + EQ(head, Qhash_table_size_marker) || > + EQ(head, Qhash_table_test_marker) || > + EQ(head, Qhash_table_weakness_marker) || > + EQ(head, Qhash_table_rehash_size_marker) || > + EQ(head, Qhash_table_rehash_threshold_marker)) > + { > + tmp = CDR_SAFE(tmp); > + val = CAR_SAFE(tmp); > + /* > + debug_print(head); > + debug_print(val); > + */ > + /* how do I turn head into a symbol with the same contents but beginning with ':'? */ > + params[param_count] = head; > + params[param_count+1] = val; > + param_count+=2; > + } > + } How 'bout: { Lisp_Object params[10]; params[0] = QCsize; params[1] = Fplist_get (Qsize, tmp); params[2] = QCtest; params[3] = Fplist_get (Qtest, tmp); params[4] = QCweakness; params[5] = Fplist_get (Qweakness, tmp); params[6] = QCrehash_size; params[7] = Fplist_get (Qrehash_size, tmp); params[8] = QCrehash_threshold; params[9] = Fplist_get (Qrehash_threshold, tmp); } and then use Fplist_get (Qdata, tmp) to get the data? > + if (NILP(data)) > + error ("No data marker was found in the hash table"); Why bother? > + while (!NILP(data)) > + { > + key = CAR_SAFE(data); > + data = CDR_SAFE(data); > + val = CAR_SAFE(data); > + data = CDR_SAFE(data); > + if (NILP(val)) > + error ("Odd number of elements in hashtable data"); This test doesn't look right. What if the value stored for `key' is indeed nil? You could write it like that instead: while (CONSP (data)) { key = XCAR (data); data = XCDR (data); if (!CONSP (data)) error ("Odd number of elements in hashtable data"); val = XCAR (data); data = XCDR (data); -- Stefan