From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on starla X-Spam-Level: * X-Spam-Status: No, score=1.2 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_GREY autolearn=no autolearn_force=no version=3.4.6 Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [94.130.110.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 2B4891F542 for ; Fri, 19 May 2023 10:04:58 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; secure) header.d=ml.ruby-lang.org header.i=@ml.ruby-lang.org header.a=rsa-sha256 header.s=mail header.b=w1RkYjwh; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sendgrid.net header.i=@sendgrid.net header.a=rsa-sha256 header.s=smtpapi header.b=pIeV3uAh; dkim-atps=neutral Received: from nue.mailmanlists.eu (localhost [127.0.0.1]) by nue.mailmanlists.eu (Postfix) with ESMTP id 789377F47F; Fri, 19 May 2023 10:04:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1684490689; bh=8cHBmGr+34MVVZjc5gxahsfFnXdH0Rs584ggij0VSlE=; h=Date:References:To:Reply-To:Subject:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From:Cc:From; b=w1RkYjwhdgtqkFLSSNIDNtYtTJdJT9+pJkVGsbdFfAwcDwGuuBu2TrJFTBS8fNU39 PsyD4PCVDRuC3msKJCroNqODr45XkaY8I2CfCHUtzmhsfxOAS9X3CAed6/RVMB00ei a/fLsJ1PRcZ2SuOl3M2my+lwzzquN8AfV7NUuXbc= Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by nue.mailmanlists.eu (Postfix) with ESMTPS id 4070E7F473 for ; Fri, 19 May 2023 10:04:45 +0000 (UTC) Authentication-Results: nue.mailmanlists.eu; dkim=pass (1024-bit key; unprotected) header.d=sendgrid.net header.i=@sendgrid.net header.a=rsa-sha256 header.s=smtpapi header.b=pIeV3uAh; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sendgrid.net; h=from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc:content-type:from:subject:to; s=smtpapi; bh=Fnvj4r7qJBcrzehE6HSO1msFXohU4KqI9PBV+cb1VxU=; b=pIeV3uAhwgkjF8DbcGXuWpUZIC99VZxDPcnqH5LiWf0v5zbGVFZpCI+loK6I6xz/60QA vQJjwOgD9QZmPIJYlvX+3r2xbvcjikID8eJrtR6y+RpKr7xWjwltfulTGphZHV3xddQAA2 rcRdwlD4uZtgkq2DoSEbMYQagozq2NsV0= Received: by filterdrecv-65f68489c8-knmdt with SMTP id filterdrecv-65f68489c8-knmdt-1-646749BB-3 2023-05-19 10:04:43.068712734 +0000 UTC m=+728925.004649032 Received: from herokuapp.com (unknown) by geopod-ismtpd-0 (SG) with ESMTP id A5VA_7MPRmKuM-2LoCPVxA for ; Fri, 19 May 2023 10:04:43.022 +0000 (UTC) Date: Fri, 19 May 2023 10:04:43 +0000 (UTC) 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: 89989 X-SG-EID: =?us-ascii?Q?Dq8GNIcVqP8cs5uR+EIAabfg3LE9XdC6dZ5KYNrMpf5bJUGvMwuCLNqEHGYs9D?= =?us-ascii?Q?Aya2vt4SFcifFg8hIA5F5H2JrQG7mCKgiS4OPE8?= =?us-ascii?Q?nWRywJMNm5talTCzqjCNBEWccBYkvFCdT=2FnxjWi?= =?us-ascii?Q?G+wl7lrfwS4HkrOtN2PG85m55aZ0PEJ7=2FlB3Kxt?= =?us-ascii?Q?J=2FdTyv31Oe8CZh=2FzxaYm3VG=2FtvPtBHSFkofQgvA?= =?us-ascii?Q?9rahiCdgqc6b4xMLzf+u=2FXsYVl1rMwcWpGPjDwS?= =?us-ascii?Q?IHNcfWHUim2MEUnxapOng=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== Message-ID-Hash: 75V5J7LCVHG33ZXAQBSQF5G4WZM5RFJN X-Message-ID-Hash: 75V5J7LCVHG33ZXAQBSQF5G4WZM5RFJN X-MailFrom: bounces+313651-b711-ruby-core=ml.ruby-lang.org@sendgrid.net 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:113528] [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: From: "byroot (Jean Boussier) via ruby-core" Cc: "byroot (Jean Boussier)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #19236 has been updated by byroot (Jean Boussier). This was discussed in the last dev meeting. The conclusion was: > In 3.3 it throws error all keyword arguments to Hash.new. Then Ruby 3.4 allows that Hash.new will accept capacity keyword argument. ---------------------------------------- Feature #19236: Allow to create hashes with a specific capacity from Ruby https://bugs.ruby-lang.org/issues/19236#change-103156 * 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/