From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p27C0jbJ024826 for ; Mon, 7 Mar 2011 13:00:45 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiACAFJXdE1KfVK2kGdsb2JhbACmQQgVAQEBAQkJDAcRBCGjVoxEhEuJCgEBAwWFXQSMMIVkgnY6gRY X-IronPort-AV: E=Sophos;i="4.62,276,1297033200"; d="scan'208";a="101455801" Received: from mail-wy0-f182.google.com ([74.125.82.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 07 Mar 2011 13:00:40 +0100 Received: by wyb32 with SMTP id 32so6023608wyb.27 for ; Mon, 07 Mar 2011 04:00:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:in-reply-to:references:from :date:x-google-sender-auth:message-id:subject:to:cc:content-type; bh=PvGzZYGRnGlpWwp8ZVQ7hb9ELfJIqLCfKHoGdg39s84=; b=LxNiXEOhHq6qmy0cAuAiTt/GlSYkVNMyv46uIvX17sP07cWBRAzfZ5HftgGQ+mASpS ajB1h9HhBY4PNz6+/5tiEwxMRKA0rxhfqzR1X/MDqQ/A8U3TDTPxjcL/HI4A7VFtPjGl z5gLIXxfKYffjaDtdAWZUyawP5PjaZ1lLxc8c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; b=Kq5wL8OSvaesZtHBZUNatUsjrjABG7FezwYObMtGIqHacFNFkjHHRK9nr2W89ZFwHs fMo//99pz2fA5Lb6wESuiD7fUOjAYt4U1sh3YbzgbbiiCuPrqXMNOTRqFL+lmyj01pBS 0Wg1dInP7eRrRg83e4SxGuiq/AGuWAp7j5ueE= Received: by 10.216.142.199 with SMTP id i49mr2149840wej.33.1299499240128; Mon, 07 Mar 2011 04:00:40 -0800 (PST) MIME-Version: 1.0 Sender: dapilki@gmail.com Received: by 10.216.154.3 with HTTP; Mon, 7 Mar 2011 04:00:20 -0800 (PST) In-Reply-To: <1299479990.22876.15.camel@azayaka> References: <1299479990.22876.15.camel@azayaka> From: Alexandre Pilkiewicz Date: Mon, 7 Mar 2011 13:00:20 +0100 X-Google-Sender-Auth: _titN3wWofIL0nChGDYjWyXmgZ0 Message-ID: To: Arlen Cuss Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [Caml-list] Hashtbl: find and find_rec Hi 2011/3/7 Arlen Cuss : > Hi all, > > I'm puzzling over the OCaml source, and am trying to work out the reason > for the following definition: [snip] > My only guess thus far is that it's cheaper if we don't recurse (stack > doesn't grow as much, fewer branches), and thus a few levels of testing > are put in for good measure to speed up the case where it's one of the > first three items. > > Is this it? Or am I missing something else? I don't think stack is smaller since the find_rec function is tail recursive. So it is basically loop unrolling (fewer branches). What I don't really understand is why only do the unrolling on the 3 first iterations. As soon as we have an unrolled version, why not calling it recursively?