From patchwork Mon May 13 08:35:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 1934609 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=a+7v+Hep; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VdCXq2rR4z1ymw for ; Mon, 13 May 2024 18:37:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9BA2E386F464 for ; Mon, 13 May 2024 08:37:29 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 0F42F386F464 for ; Mon, 13 May 2024 08:35:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0F42F386F464 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0F42F386F464 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715589391; cv=none; b=j+UKeFvuiO7VfOggGbqWuWCYIMs+oo6MXytNGVcM7mVbSSb6WMZ2gG5v7Z56C3RVbGslFfphE755GhfATCWiW/v1zJEFMdhucB2I3eQj7bU+Uxr4lcPtpEMhn/fRRXCaBpzhhDetEf9K9ovL+jlcdEFEzrJ7PwjCXJn4FgYGnz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715589391; c=relaxed/simple; bh=Dq8lbm9GQ7UJ+Ik75RvSbYoe+re1M0Rua9Fkvw/Ns8Y=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=kF0yDWITi19f0QvfXC0F3svX8EgXiq3XOWuOtG/kAZfcux3A7Yxo+dUZBv55aS2ZAqEy9bT+M8lsYcZK8iTTOuE6HKKkibe201+8HuWS5AGy7kLUmWuBhn+0iTD8MpFr5SpOe0/ReSpNXCTVAHOECF+Ut1VZGaUbENLGkYeeHhc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-34d7d04808bso3130541f8f.0 for ; Mon, 13 May 2024 01:35:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1715589345; x=1716194145; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=cCX12eqLAF3tg0su5AUtIc57BrzUvu8raMaxPjddroo=; b=a+7v+HepPPCn3PB5LJ0thuRbnCHbvM1BGHGHEtR2lNZyd/aJsgLIXPAKWaIwVqmqhV 3jAjufN0FEAvuh0Ys0uBWai8E0Gfy+XAMgOwIRNOMN3mUByPia4ENaE7ZLiZfabPmqMw kjIK4Z6XTJr3mqujYtiLk8agxS1ciTMRt1vHWWVm39RECT94cBdOj5YdUFgfEYVkQrOI mqYuCJfytiN6VukWbz1rfa/JyGqZzGfhju+nQdVpEsulsgZ7RYRVMzAvIaMdFR1xN03B 5VpqeiB1wVtDONK/e9cXCom/xVfraP5cBGFAnDDsde7NUfCcoNvryBme1PLJmW7ZvC7e 5bKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715589345; x=1716194145; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=cCX12eqLAF3tg0su5AUtIc57BrzUvu8raMaxPjddroo=; b=o8d4lF3BelFO07cSf/Ba1/cLal8IVCLzK3JhM2y+RTYRDaek//C700wuwGh03QBhVP RZX7rkeZYeDP5EJvS9uliQ+BOteQApYhhSUi+UCrg++gAmqatHG31xo9rho+S9tQzc4a QtgNAC5E71feiXl+tFJhc0KE6RNeFOwW+hkWcQJjpDesBp+XVlPhngFh2Mbx1uUSKnXO oM++xMoL1Jp9859ZOodV7uIYjUMl2U3TrxSa/ADFq1dwvmxlzZLGLlbrcXPm8UbmSPQu FiYmV1mi/th3g5A+RSoq2wxYCTdS36xhYCjfRyc4uqMB/gEBc3sMhMfi0e+4wW74hMsq B43w== X-Gm-Message-State: AOJu0YwLVd6WK4iiyAg8mjJjGDq3badmOdHQPi3zTHEJgq5VpLMeCXhA s5cbSn7v9/DJ2Htu6sLUjmEwKAEeXv5uKoFYLyvWzFLcJi8u+niGcfdG/6CwYxbdmIiZRF/JaTA = X-Google-Smtp-Source: AGHT+IHXmCn6ikQbXIlrAU3ju7nHdXa8ArvMnWaR7V8xpR4oB5Am9Y6ZWKbSU/z1oK43YdwFSIMQ+g== X-Received: by 2002:adf:e902:0:b0:34a:77af:50cf with SMTP id ffacd0b85a97d-3504a737657mr10321974f8f.36.1715589344643; Mon, 13 May 2024 01:35:44 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:cf0f:cd6c:7a6a:cbed]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3502b896a29sm10531260f8f.43.2024.05.13.01.35.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 01:35:44 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED] ada: Refactor GNAT.Directory_Operations.Read to minimise runtime checks Date: Mon, 13 May 2024 10:35:43 +0200 Message-ID: <20240513083543.164532-1-poulhies@adacore.com> X-Mailer: git-send-email 2.43.2 MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org From: Piotr Trojanek Array assignments are likely more efficient than element-by-element copying; in particular, they avoid constraints checks in every iteration of a loop (when the runtime is compiled with checks enabled). A cleanup and improvement opportunity spotted while working on improved detection of uninitialised local scalar objects. gcc/ada/ * libgnat/g-dirope.adb (Read): Use null-excluding, access-to-constant type; replace element-by-element copy with array assignments. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/libgnat/g-dirope.adb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/gcc/ada/libgnat/g-dirope.adb b/gcc/ada/libgnat/g-dirope.adb index c23aa68b700..428d27d9e8d 100644 --- a/gcc/ada/libgnat/g-dirope.adb +++ b/gcc/ada/libgnat/g-dirope.adb @@ -676,13 +676,9 @@ package body GNAT.Directory_Operations is return; end if; - Last := - (if Str'Length > Filename_Len then Str'First + Filename_Len - 1 - else Str'Last); - declare subtype Path_String is String (1 .. Filename_Len); - type Path_String_Access is access Path_String; + type Path_String_Access is not null access constant Path_String; function Address_To_Access is new Ada.Unchecked_Conversion @@ -693,9 +689,13 @@ package body GNAT.Directory_Operations is Address_To_Access (Filename_Addr); begin - for J in Str'First .. Last loop - Str (J) := Path_Access (J - Str'First + 1); - end loop; + if Str'Length > Filename_Len then + Last := Str'First + Filename_Len - 1; + Str (Str'First .. Last) := Path_Access.all; + else + Last := Str'Last; + Str := Path_Access (1 .. Str'Length); + end if; end; end Read;