Message ID | 20240202155825.314567-26-masahiroy@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-50085-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp527769dyc; Fri, 2 Feb 2024 08:06:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGPu8qG1MIV+3c0ZN8anTUn9t6d6NaLgwmHzURRr5s+MmdGvYU5ECT1fhrcRK5VvFnVAevE X-Received: by 2002:a05:622a:1a09:b0:42a:4350:64c7 with SMTP id f9-20020a05622a1a0900b0042a435064c7mr2703646qtb.68.1706889977142; Fri, 02 Feb 2024 08:06:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706889977; cv=pass; d=google.com; s=arc-20160816; b=bkY9LXqguYz/UBQXW+1kq/Fshn2xg08aZGz5QGx505F1/5H60hKUKtkwDLQ3uv5U6V D22k5k1LTLd7jhxs4pu+j3zta2nF2FJQ4cJSRhV3ZEH7R9tnlFcw13Hc8JngsrpDmb4r R7BkyoPtwGNYe40lCqJVqLZHh+TtjwZY4T7M/y3LMdbPYEcZHJqyZca5fuPjLNPiNbMl TrZ8cBB2jUe8T+rDYwP9UyBO/abtEb97VmFEtJOd85lYUHn7PlpXOqeDEgDgRmJ6iBEH mYKzzJmtViVSoZLbw0VVcJK91fgQDdQQdcClYb0DG10ofXBwUbcCd2VefnnRr9HbfHR7 RSlQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=gMxmTmFFHZc9BjIVn1FY+o0s5+6GqOc2ntS4B8JVFgE=; fh=u8aShW3KCbxmw+VDFad5nvR1xg5gyc/+a7Sl0zNK3bA=; b=khYF3AyfC9wNL0jRCsLGltmtKloJL3UhOlTklByM6Zdz8/wTEYjnlwVpJ5LtWteVMf GKtPmy0deg9QYEAh/UcUA9NQ6RKTubn1dG+QAIseB8j4B/Jjnlk7z+BKU8M1Wwd1E+hh 8vIXHOLYaL+NqiXQyy/dbjOl5fZbDbcZ3V+l6rotPdwfKQEsZZlrk3HXVA8f8WqcrJ19 zTwZiNQK1i6H1k6+eKRTwD72OkAMD8HJ+G8GsaAtXJrz3xY3ucM93nBrvGd094ZmlpdV p6CbTQ1gkbZnax0RHtprnv1mi/+Vnlfak3reiecPL2S9jRnUop12+t8uLyNMeykbAooW p6TA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ruhFwbtw; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50085-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50085-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCX3jGCtKHrkieA4KOkzHt6AAU2acMKagTh9JWnjb/VJYAuMudDKTH4CaNOXYDHrccYcgDUbAG1LQpQqRnDM6/W1Z1YbdQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f8-20020ac859c8000000b00429c6bc50a4si2202422qtf.528.2024.02.02.08.06.17 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 08:06:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50085-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ruhFwbtw; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50085-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50085-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 78A651C252CC for <ouuuleilei@gmail.com>; Fri, 2 Feb 2024 16:05:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 17755153BE0; Fri, 2 Feb 2024 15:59:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ruhFwbtw" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 662B5151CF4; Fri, 2 Feb 2024 15:58:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889538; cv=none; b=ZwFKWZmXplKlHChirBOhDFliu1r94yjwY/jYY/3zSLFpAw2q4iYHhncbQvV8RKGaSN6fB2McH+m4QiLL891xHxysoxfP88TMwOEGbifnP8WyBubwYU5CQ6a4pmff86TKFEzk6ftGJTjeSb7gecqiUhDnUzAQBgHYiUTjhTKS6jM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889538; c=relaxed/simple; bh=X8I9rXVeGCoi7QcnwK71myLC6oWao8zTKDKpyMAWvVo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=q02AA6ixz2XkoF09bp+idYDM3ey6oXXHaJCRKcg6zOk6Sa9IUfGcrLDJkakwWYxMIyCJOk5h6vMx4Ns1Gr0/TZdP90mMrniU8Ec1uYFsCU4x9w5zf35Yf9zMFJKNpFQlNp05YHeqROwa0ex+faZgpsN3eh6X8SoN25EYB52j7xo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ruhFwbtw; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95B95C433F1; Fri, 2 Feb 2024 15:58:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889538; bh=X8I9rXVeGCoi7QcnwK71myLC6oWao8zTKDKpyMAWvVo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ruhFwbtwadYQ+aNHjKCd11eXVlQ7wLThqD6C1mWZNU+jhMKHpQ2auVnO/eSPsB6+u 37fcPp48rAWE7w8tmgQYNgB205Io0CJL1RzBt5MN6MVDulVdvkZNXNS8yyzBeOD6dq 0Nuy2uyWp560OU3J+py8kfOlcsRxjitACuxs778wcKnhtQP4/ufG5yFAdmDGuoBFUy ZxBG8KGyl8XEzY4hpEvAmUzyXcrdsHLpFF4Wzscwb/kSbDEO62qKYMtqehjee25PRx 6yij5ztam2Vo9vMKZwrkOgVwit0UIp5GpPcAB4KTMVDWxZZVr0SljfNwNju0I5yHT9 8LliXU3QuTMug== From: Masahiro Yamada <masahiroy@kernel.org> To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada <masahiroy@kernel.org> Subject: [PATCH 25/27] kconfig: convert linked list of files to hash table Date: Sat, 3 Feb 2024 00:58:23 +0900 Message-Id: <20240202155825.314567-26-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240202155825.314567-1-masahiroy@kernel.org> References: <20240202155825.314567-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789803864443922570 X-GMAIL-MSGID: 1789803864443922570 |
Series |
kconfig: refactor lexer and parser code
|
|
Commit Message
Masahiro Yamada
Feb. 2, 2024, 3:58 p.m. UTC
Currently, a linked list is used to keep track of all the Kconfig
files that have ever been parsed. Every time the "source" statement
is encountered, the linked list is traversed to check if the file has
been opened before. This prevents the same file from being recorded
in include/config/auto.conf.cmd again.
Given 1500+ Kconfig files parsed, a hashtable is now a more optimal
data structure.
By the way, you may wonder why we check this in the first place.
It matters only when the same file is included multiple times.
In old days, such a use case was forbidden, but commit f094f8a1b273
("kconfig: allow multiple inclusion of the same file") provided a bit
more flexibility. Of course, it is almost hypothetical...
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/kconfig/util.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index 610d64c01479..abd697ed8de7 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -7,34 +7,37 @@ #include <stdarg.h> #include <stdlib.h> #include <string.h> + +#include "hashtable.h" #include "lkc.h" +#include "util.h" + +/* hash table of all parsed Kconfig files */ +static HASHTABLE_DEFINE(file_hashtable, 1U << 11); struct file { - struct file *next; + struct hlist_node node; char name[]; }; -static struct file *file_list; - /* file already present in list? If not add it */ const char *file_lookup(const char *name) { struct file *file; size_t len; + int hash = strhash(name); - for (file = file_list; file; file = file->next) { - if (!strcmp(name, file->name)) { + hash_for_each_possible(file_hashtable, file, node, hash) + if (!strcmp(name, file->name)) return file->name; - } - } len = strlen(name); file = xmalloc(sizeof(*file) + len + 1); memset(file, 0, sizeof(*file)); memcpy(file->name, name, len); file->name[len] = '\0'; - file->next = file_list; - file_list = file; + + hash_add(file_hashtable, &file->node, hash); str_printf(&autoconf_cmd, "\t%s \\\n", name);