From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx08-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by sourceware.org (Postfix) with ESMTPS id 3C1E33858430 for ; Fri, 15 Dec 2023 10:28:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C1E33858430 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=foss.st.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3C1E33858430 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=91.207.212.93 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702636124; cv=none; b=HAidn4zEuBWyjnv8KTwB6IlRpSpzWNUlaJM91X2bCzBLwOr6AD/P4nhF36gvcoM1DQFH/+tHqqq9A3PrykHkf2htJDqqdqhPMuhB8ZByZbDOEMQoblj8LacvKdQ7Tk0K3HCswxAPlTVIs8jE+Ghyvkr+ERkLUav9qHq5GWeb2IY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702636124; c=relaxed/simple; bh=18sLc81Ec4HOpLbIq1oErPO1KIuMftwR2kP6PoN/i84=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=G+ktgh1xGiciY98k1NxU7LjvMklIE4nUzAHSYXP2hjB+UmietNWXG8M/uCdc6enY5kuCMbs4XK+8NV2/uutrN2ya27Tm83BjPh26lre+DeUYvROM/KyXXuZuSF+c0xNyBzBlgmofoM/blXyguuKKyGLZz6v5ybMT71BDxAGeK1c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0369457.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 3BF9Xaod016122; Fri, 15 Dec 2023 11:28:24 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s= selector1; bh=3jsWk0IhZ+s7V7z5siGH7+hdo3MQA+y4d/TtjYgOmpc=; b=ft 690j34PzcfhfGVRaNgWbW5sybIDgWNddROFOfJzGTql5n6rHgmfU8EhUuQmU6wyy pu2/P79thviD70fA6ORS0fvCGxDHIQimrmDnhnlulwAw1KrP6aywVnPFI757zQ5/ whYt+TQY70C9IOdPGIvLKx2yaIKDeYjLcuHGPl7M+If9yAonO1/DJvYqBXLYrBsY rOLBatohMj+nZVJ7HE5Kcg7/zPmu1r7d9QYGbUDgt23mmH6Vm599AceIRu6e0INh YoOI5WvsfiIQhCVoRIdYRCT608FfiQsr1rqqL7baZzTkVFd2Hjk/8i2Jcfeh6TbO OGIHm+zKsag9lOb1ELbA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3uw42nxxrg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 15 Dec 2023 11:28:24 +0100 (CET) Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id CE4C4100052; Fri, 15 Dec 2023 11:28:23 +0100 (CET) Received: from Webmail-eu.st.com (shfdag1node3.st.com [10.75.129.71]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 84B9A210F89; Fri, 15 Dec 2023 11:28:23 +0100 (CET) Received: from [10.252.3.168] (10.252.3.168) by SHFDAG1NODE3.st.com (10.75.129.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Fri, 15 Dec 2023 11:28:22 +0100 Message-ID: <70b09ef7-fe4a-4669-ad27-2bd6c8bdca61@foss.st.com> Date: Fri, 15 Dec 2023 11:28:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] newlib: libc: Improved the readability of strcspn with minor optimization Content-Language: en-US To: Xiao Zeng , CC: , , References: <20231215083101.5643-1-zengxiao@eswincomputing.com> From: Torbjorn SVENSSON In-Reply-To: <20231215083101.5643-1-zengxiao@eswincomputing.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.252.3.168] X-ClientProxiedBy: SHFCAS1NODE2.st.com (10.75.129.73) To SHFDAG1NODE3.st.com (10.75.129.71) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-15_06,2023-12-14_01,2023-05-22_02 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hello Xiao, On 2023-12-15 09:31, Xiao Zeng wrote: > Signed-off-by: Xiao Zeng > --- > newlib/libc/string/strcspn.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/newlib/libc/string/strcspn.c b/newlib/libc/string/strcspn.c > index abaa93ad6..8ac0bf10c 100644 > --- a/newlib/libc/string/strcspn.c > +++ b/newlib/libc/string/strcspn.c > @@ -37,12 +37,10 @@ strcspn (const char *s1, > for (c = s2; *c; c++) > { > if (*s1 == *c) > - break; > + goto end; > } > - if (*c) > - break; > s1++; > } > - > +end: > return s1 - s; > } Just looking at this small snippet of code, I would say that the previous code and your suggestion won't do the same thing. Do you have unit tests that confirm that the behavior is identical with the current implementation and your suggested change? When I run your suggestion, I get return value 0, but with the current implementation it's 3 for this call: strspn("129th", "1234567890"). Kind regards, Torbjörn