Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lKuM6-0006cm-EL for pgsql-hackers@arkaria.postgresql.org; Sat, 13 Mar 2021 02:50:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lKuM5-0007jb-CJ for pgsql-hackers@arkaria.postgresql.org; Sat, 13 Mar 2021 02:50:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lKuM5-0007hp-2b for pgsql-hackers@lists.postgresql.org; Sat, 13 Mar 2021 02:50:17 +0000 Received: from mail-il1-x133.google.com ([2607:f8b0:4864:20::133]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lKuM2-0001RI-KY for pgsql-hackers@postgresql.org; Sat, 13 Mar 2021 02:50:16 +0000 Received: by mail-il1-x133.google.com with SMTP id e7so4383876ile.7 for ; Fri, 12 Mar 2021 18:50:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GNb1sn2VonQ8u2GOxn24AGLlgAQ9urxDYRyUtTVyTDE=; b=ecc7eYGx/X/gGjzvdghKNV8/aR6lx/wWjUWC1mmg9sHWQYieUdRjZHaUkmgTSAIJT1 orDqo2DWcmOlb/m4y4wGi5MnDb8E0MdvWUDt00xO23idj6i000bQp2VT2pAuJISVA1yu 2Q8cjJZObdmUxNG6ZDpDqyk8vSrCy7zf/PZOXux82SK2uRM/3J0mRqH75ntDeGqL/yHT JsrLdwwKwTfIMRyyoPk2xpLvfeh+ZOyQbXbE9wKDpfDyUrDeSzkso7yfyIEhdLTkMZiX u+/NQRpn/CTDQkcioBqp9ECLXPFYVbyPhgq8tvYjiO15hSShEVGz1L1gAXOPJY+y4vuP MQDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GNb1sn2VonQ8u2GOxn24AGLlgAQ9urxDYRyUtTVyTDE=; b=ISxQl+YAfca4zwTaAqb2uYCn5ZFLk+neSNQvDMrGNCUXHC2ydAUtidjOaXmbyHR0In PpyC9kv9FkpyTzQZb6ARZ/ZsOrJxIV5LTyA1MvnAYloGXxh9k1lGFgr9yxO5zRfmmcB+ HYBMiJwLpoPLDufbh93DnWr1zbCTJFHOX2HPT6wHvzQrF+Y73NQP/dR7SRP7jSXswvUR NAMnK2gd0XilJsPgW1mVsGN7iSZUL+byvA0s8ka6gvFk7H3q4pPTgf+JShEg0rLfpT/q puvHZ3+QTC80oysvB/11TOIyBQeRtIV+wxl9S2obHENnbbjFLD6BT3uyyCtsvzWIvyf1 KkWQ== X-Gm-Message-State: AOAM531I79Js279YBrvU1/ZOMqhznRqrmkAOfSnus+2nZN+ShZdPIH83 nj7gOq/jX+n+w+l+HKrsK9w1yd0Qi/UogKPCR3bzZhlIWRY7sQ== X-Google-Smtp-Source: ABdhPJxd1b012ewa8bqnlruorN3H3L4uzpQFiKaTN8xcS5gWFvK3X2k7lnQ0BJKvCZ6OH0reziWd/bwGnCcbeso+Wsg= X-Received: by 2002:a92:7613:: with SMTP id r19mr3896459ilc.41.1615603812999; Fri, 12 Mar 2021 18:50:12 -0800 (PST) MIME-Version: 1.0 References: <0F9ECBA9-1DF2-4C38-BB58-B17EEE6C7B3A@yesql.se> <20210311185847.zwb2rf3n4wzelkba@alap3.anarazel.de> In-Reply-To: <20210311185847.zwb2rf3n4wzelkba@alap3.anarazel.de> From: Thomas Munro Date: Sat, 13 Mar 2021 15:49:36 +1300 Message-ID: Subject: Re: A qsort template To: Andres Freund Cc: Daniel Gustafsson , pgsql-hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Mar 12, 2021 at 7:58 AM Andres Freund wrote: > I wish we had the same for bsearch... :) Glibc already has the definition of the traditional void-based function in /usr/include/bits/stdlib-bsearch.h, so the generated code when the compiler can see the comparator definition is already good in eg lazy_tid_reaped() and eg some nbtree search routines. We could probably expose more trivial comparators in headers to get more of that, and we could perhaps put our own bsearch definition in a header for other platforms that didn't think of that... It might be worth doing type-safe macro templates as well, though (as I already did in an earlier proposal[1]), just to have nice type safe code though, not sure, I'm thinking about that... [1] https://www.postgresql.org/message-id/flat/CA%2BhUKGLY47Cvu62mFDT53Ya0P95cGggcBN6R6aLpx6%3DGm5j%2B1A%40mail.gmail.com