From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from mail-io1-f48.google.com (mail-io1-f48.google.com [209.85.166.48]) by gnuweeb.org (Postfix) with ESMTPS id 51F577F62C for ; Thu, 12 May 2022 16:54:45 +0000 (UTC) Authentication-Results: gnuweeb.org; dkim=pass (2048-bit key; unprotected) header.d=kernel-dk.20210112.gappssmtp.com header.i=@kernel-dk.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=BSwvYcRm; dkim-atps=neutral Received: by mail-io1-f48.google.com with SMTP id s23so5983392iog.13 for ; Thu, 12 May 2022 09:54:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=UKhmd335kQgjiMaXmtA8s5aPI0NV040m7EKrqeMdxMs=; b=BSwvYcRmsGdJETn8iqVwvnIpw2qBWrZ6tdAaSFWyRrrvErTfW4qzuyxSxT/rEMjxpY vX3gh+hT4cYLKtveJQJVh9LJYPqisd6IxQK3QxyNiRZ8grQD2nomPl5wdrHgm8U7djV+ s7eufvJWjaFEubXONJU/X5Ioe5ux9bxJd4ee6cIRnG2yRr6VL3h+aJNv97OYxObmWZIT rGqNxRBH0Vv6BBd/J5Kt9wfLvCqP+lqh9rTFmIwzyyn4kBrQLrfSX9Gx4B1+No28HgW7 Qp8R429/jWMqvzqlShOeNMMhEblG6W8g1RDjWUU4uqTZue4Kid8cNbNmDAKKiFAvkFrx m7ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=UKhmd335kQgjiMaXmtA8s5aPI0NV040m7EKrqeMdxMs=; b=FydAWzOItqIw7yme4W0gt8AttHRqCCd3WnkwA7EUDTEXzERHD7zI1yI8K975jyeset cH8F0e79EgArPyxT85C9hKNA1OMzAuTdzAZlC6UIdz9H0ybaZ5+K1WT151x8XdsGw/IQ FaTt0+UQ/JYDnHqidNmgA1fo4KgnBkdYsV+LONhE+3+Gz6ovcLnmT6jTKEQgnTT/LJFA DwYvLWusGXDHrjnEltfPbx0C6tf1ijvb2yckukBvT/4kdfxbhCZyJhHaUH2l8DqoJzxS nNcLQbx3suxN48KKm1eRqs7TW/5O+2wCYNPPEnKuNfVUJub0GbIh/nrmCsgZoF76YBZR yozw== X-Gm-Message-State: AOAM533jB4dTdCaSk/V2AYgBTVbH3gDCGElDshp4e9H4xuSQJSY0vTVQ lMoyP/Oy6+evcFUtKP5RMu3xuw== X-Google-Smtp-Source: ABdhPJx4dW4z1zbBTDyrF6Pnx4J/qo3AM2BR4dyLfb8cs3p85Ouq3Ft/V/E0zh48LU8UpZErDxSYyw== X-Received: by 2002:a05:6602:1614:b0:65a:c414:5aa0 with SMTP id x20-20020a056602161400b0065ac4145aa0mr475633iow.60.1652374484273; Thu, 12 May 2022 09:54:44 -0700 (PDT) Received: from [192.168.1.170] ([207.135.234.126]) by smtp.gmail.com with ESMTPSA id w197-20020a022ace000000b0032b5e4281d3sm9811jaw.62.2022.05.12.09.54.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 May 2022 09:54:43 -0700 (PDT) Message-ID: <7c486e95-e0bc-a991-67b3-97cbbfe9e20b@kernel.dk> Date: Thu, 12 May 2022 10:54:42 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH v4 2/3] json: Change `if (!strlen(str))` to `if (!str[0])` Content-Language: en-US To: Ammar Faizi Cc: Niklas Cassel , fio Mailing List , GNU/Weeb Mailing List References: <20220512164333.46516-1-ammarfaizi2@gnuweeb.org> <20220512164333.46516-3-ammarfaizi2@gnuweeb.org> From: Jens Axboe In-Reply-To: <20220512164333.46516-3-ammarfaizi2@gnuweeb.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: On 5/12/22 10:43, Ammar Faizi wrote: > No need to traverse the whole string. Using `!strlen(str)` as a > *conditional expression* is effectively the same with `!str[0]`. > > Reviewed-by: Niklas Cassel > Signed-off-by: Ammar Faizi > --- > json.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/json.c b/json.c > index cd3d5d74..8b650721 100644 > --- a/json.c > +++ b/json.c > @@ -56,7 +56,7 @@ static char *strdup_escape(const char *str) > char *p, *ret; > int escapes; > > - if (!strlen(str)) > + if (!str[0]) > return NULL; This seems like a useless optimization, strlen() should already be doing this. -- Jens Axboe