From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90358C433EF for ; Fri, 15 Oct 2021 00:40:24 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9BEA4610A0 for ; Fri, 15 Oct 2021 00:40:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9BEA4610A0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B7B98836A6; Fri, 15 Oct 2021 02:40:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="X5A14G8u"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F3B3C836B5; Fri, 15 Oct 2021 02:40:18 +0200 (CEST) Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3037883689 for ; Fri, 15 Oct 2021 02:40:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@google.com Received: by mail-ot1-x333.google.com with SMTP id 62-20020a9d0a44000000b00552a6f8b804so10004191otg.13 for ; Thu, 14 Oct 2021 17:40:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=KvoMCt6g+KlF5p2/OB83d1dsk4jjizmGhrW7Rxcn/Jg=; b=X5A14G8ucXJ8u26DzHAgp+jwirG+FaNEU7F7ZI/AqA69dWFctlm+egyCull+FNDQdW BgrFL/xNIIP8DPXfY2ojmx2A5MNXkkyAnAAp9dJJ+mh6jq2kUe5KxyrovUL1V8YCPQbl R0rcL4jpt2RUIaenjNL6dKhxSfpg24VL2MXZI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=KvoMCt6g+KlF5p2/OB83d1dsk4jjizmGhrW7Rxcn/Jg=; b=Nnrfd0WXZKtsStVHSQGDOvX+U0OopNxxuvjxcvIWQ6mRmj2SDTiCSPVRJ3eH/4cQbR m2yzRUcFMdJJvr4QF3/tq3YOMc1SJ9G/t4Znwdl0Sb7XWUomS/yq0FLApvSU88bshQxI 9zo9JUwm3S65wYOoUhHsZMKuuG62Fjdj526TK33y8ycM2OXIpQ61mhlubW9fAWSiLeQR NvrmxiNbw009eSSAHURf9/KY/+aN2CqNvEYB2YYIpuPSG89vQTxdhwP1mTqCtWXNyLXK mXQSgk6kyMPvFwYYVP23z+F9XmR5Jwi4N5+kMpAwoYWI7TgOzXP/9wnHmGkGqe88C2zH Iy0w== X-Gm-Message-State: AOAM532c4jJTg0OrGUMDthGr3QzACUC5r+ZboouDI4sotamBj7HR6nuw +QJXNaWJ18R6FuzkjUIhdnGrHfIZzF/DOng5BBwPDw== X-Google-Smtp-Source: ABdhPJzUyo9A/Re0z0FABEbDKeCKIoxnt0eLBgXy/Mawd1BZ9jiH5RdLmTilf0LWdIJsqCWJBmeYrKX/ceszaDVRu9A= X-Received: by 2002:a9d:17c5:: with SMTP id j63mr5638922otj.191.1634258413385; Thu, 14 Oct 2021 17:40:13 -0700 (PDT) MIME-Version: 1.0 References: <20211013154557.28479-1-kabel@kernel.org> <20211013154557.28479-10-kabel@kernel.org> In-Reply-To: <20211013154557.28479-10-kabel@kernel.org> From: Simon Glass Date: Thu, 14 Oct 2021 18:40:02 -0600 Message-ID: Subject: Re: [PATCH v2 09/13] env: Use string pointer instead of indexes in env_get_f() To: =?UTF-8?B?TWFyZWsgQmVow7pu?= Cc: Tom Rini , U-Boot Mailing List , =?UTF-8?B?TWFyZWsgQmVow7pu?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Hi Marek, On Wed, 13 Oct 2021 at 09:46, Marek Beh=C3=BAn wrote: > > From: Marek Beh=C3=BAn > > Since we no longer use env_get_char() to access n-th character of > linearized environment data, but rather access the arrays themselves, we > can convert the iteration to use string pointers instead of position > indexes. > > Signed-off-by: Marek Beh=C3=BAn > --- > cmd/nvedit.c | 34 +++++++++++++++++----------------- > 1 file changed, 17 insertions(+), 17 deletions(-) > > diff --git a/cmd/nvedit.c b/cmd/nvedit.c > index 7c99a693ea..6eabd51209 100644 > --- a/cmd/nvedit.c > +++ b/cmd/nvedit.c > @@ -706,17 +706,17 @@ char *from_env(const char *envvar) > return ret; > } > > -static int env_match(const char *env, const char *s1, int i2) > +static const char *matching_name_get_value(const char *p, const char *na= me) OK so this is the function where I would like a nice comment, please. > { > - while (*s1 =3D=3D env[i2++] && *s1 !=3D '\0') > - if (*s1++ =3D=3D '=3D') > - return i2; > + while (*name =3D=3D *p++ && *name !=3D '\0') > + if (*name++ =3D=3D '=3D') > + return p; > > - /* We can look at env[i2-1] because i2 was incremented at least o= nce. */ > - if (*s1 =3D=3D '\0' && env[i2-1] =3D=3D '=3D') > - return i2; > + /* We can look at p[-1] because p was incremented at least once. = */ > + if (*name =3D=3D '\0' && p[-1] =3D=3D '=3D') > + return p; > > - return -1; > + return NULL; > } > > /* > @@ -724,8 +724,7 @@ static int env_match(const char *env, const char *s1,= int i2) > */ > int env_get_f(const char *name, char *buf, unsigned len) > { > - const char *env; > - int i, nxt; > + const char *env, *p, *nxt; > > if (name =3D=3D NULL || *name =3D=3D '\0') > return -1; > @@ -735,20 +734,21 @@ int env_get_f(const char *name, char *buf, unsigned= len) > else > env =3D (const char *)gd->env_addr; > > - for (i =3D 0; env[i] !=3D '\0'; i =3D nxt + 1) { > - int val, n; > + for (p =3D env; *p !=3D '\0'; p =3D nxt + 1) { > + const char *value; > + int n; > > - for (nxt =3D i; env[nxt] !=3D '\0'; ++nxt) > - if (nxt >=3D CONFIG_ENV_SIZE) > + for (nxt =3D p; *nxt !=3D '\0'; ++nxt) > + if (nxt - env >=3D CONFIG_ENV_SIZE) > return -1; > > - val =3D env_match(env, name, i); > - if (val < 0) > + value =3D matching_name_get_value(p, name); > + if (value =3D=3D NULL) > continue; > > /* found; copy out */ > for (n =3D 0; n < len; ++n, ++buf) { > - *buf =3D env[val++]; > + *buf =3D *value++; > if (*buf =3D=3D '\0') > return n; > } > -- > 2.32.0 > Regards, Simon