From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET,SPF_HELO_PASS, SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [IPv6:2a01:4f8:1c0c:6b10::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 3DD441F601 for ; Thu, 15 Dec 2022 09:02:32 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.b="GU9d4B4h"; dkim-atps=neutral Received: from nue.mailmanlists.eu (localhost [127.0.0.1]) by nue.mailmanlists.eu (Postfix) with ESMTP id 028187F091; Thu, 15 Dec 2022 09:02:25 +0000 (UTC) Authentication-Results: nue.mailmanlists.eu; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=GU9d4B4h; dkim-atps=neutral Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by nue.mailmanlists.eu (Postfix) with ESMTPS id EC5547F08D for ; Thu, 15 Dec 2022 09:02:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ruby-lang.org; h=from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc:content-type:from:subject:to; s=s1; bh=mQ8gjh0f0BCkq/6VMzniVlTAHyiI5gBSSjUbe0wnErQ=; b=GU9d4B4hOYWUUzCrzCmMzRvG+KaqWdMv6GmCkldRhk+bnsbzHo+VaVoTK9uR1NOhF8/e VqlCT6Srj+Xmz2JNFo0rjQRcbTDup28VdqlarimEuE8+BEP4WWwtqLuIJzFr+huL2LURmV 9d2DLtWvXmyNhAfyuxepun7Ygd+fuZyU26Nnevdkb4XvE3282/Z2DLd++pWO6AMQKa6Tfa tx/LYmJMDSDkgoUO4MmGHTw+Pyc+UainmRoaZgBQtVV5YC3ku2qujwb5TH1j6ZkKEe8Df9 1RT0CD4YEsZ6yymEiZ7faRI7F/2OY8cu3RFSDTBT2kEurVHEFbcx5t+IAW3/RPkg== Received: by filterdrecv-6b9548745c-lsftv with SMTP id filterdrecv-6b9548745c-lsftv-1-639AE29B-4B 2022-12-15 09:02:19.539511787 +0000 UTC m=+2368454.349655765 Received: from herokuapp.com (unknown) by geopod-ismtpd-2-2 (SG) with ESMTP id oTP5qnXXSt-vHK_qn9kSLg for ; Thu, 15 Dec 2022 09:02:19.497 +0000 (UTC) Date: Thu, 15 Dec 2022 09:02:19 +0000 (UTC) From: "byroot (Jean Boussier)" Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 19236 X-Redmine-Issue-Author: byroot X-Redmine-Sender: byroot X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-Redmine-MailingListIntegration-Message-Ids: 87707 X-SG-EID: =?us-ascii?Q?Dq8GNIcVqP8cs5uR+EIAabfg3LE9XdC6dZ5KYNrMpf6VzBWG6HqArcu5raQjXL?= =?us-ascii?Q?IGTFdxKHUt7++67+KD54pNYXheirMcsUIf3sdgF?= =?us-ascii?Q?Riq06hzBN0eNqTkl8ytPk3pxvrC6JeIk46K3LOH?= =?us-ascii?Q?QQprrp15zxw1asyMAazdZCxFqGy1N3lsJAnDE56?= =?us-ascii?Q?NUnj6bkn6mMA4oX=2F3HfCguQ8lo2AOILWiCNm52M?= =?us-ascii?Q?blf5lbRhvrrZIVMyyx83SJI32=2FgCa1kMicfhOvB?= =?us-ascii?Q?EO1FFv533LQd9+lXQqZWw=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== Message-ID-Hash: BDY3CGVQ3DHVSMFGI43MQLPJBBFWVRIQ X-Message-ID-Hash: BDY3CGVQ3DHVSMFGI43MQLPJBBFWVRIQ X-MailFrom: bounces+313651-b711-ruby-core=ml.ruby-lang.org@em5188.ruby-lang.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list Reply-To: Ruby developers Subject: [ruby-core:111306] [Ruby master Feature#19236] Allow to create hashes with a specific capacity from Ruby List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #19236 has been reported by byroot (Jean Boussier). ---------------------------------------- Feature #19236: Allow to create hashes with a specific capacity from Ruby https://bugs.ruby-lang.org/issues/19236 * Author: byroot (Jean Boussier) * Status: Open * Priority: Normal * Target version: 3.3 ---------------------------------------- Followup on [Feature #18683] which added a C-API for this purpose. Various protocol parsers such as Redis `RESP3` or `msgpack`, have to create hashes, and they know the size in advance. For efficiency, it would be preferable if they could directly allocate a Hash of the necessary size, so that large hashes wouldn't cause many re-alloccations and re-hash. `String` and `Array` both already offer similar APIs: ```ruby String.new(capacity: XXX) Array.new(XX) / rb_ary_new_capa(long) ``` However there's no such public API for Hashes in Ruby land. ### Proposal I think `Hash` should have a way to create a new hash with a `capacity` parameter. The logical signature of `Hash.new(capacity: 1000)` was deemed too incompatible in [Feature #18683]. @Eregon proposed to add `Hash.create(capacity: 1000)`. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/