From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from zimbra.cs.ucla.edu (zimbra.cs.ucla.edu [131.179.128.68]) by sourceware.org (Postfix) with ESMTPS id 72FD23856276; Fri, 6 May 2022 09:25:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 72FD23856276 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=cs.ucla.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cs.ucla.edu Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 5CA9F1600DB; Fri, 6 May 2022 02:25:26 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id Yfzgelr7tL8k; Fri, 6 May 2022 02:25:25 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 9F8691600E5; Fri, 6 May 2022 02:25:25 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 54bN2FdAOsh2; Fri, 6 May 2022 02:25:25 -0700 (PDT) Received: from [192.168.1.9] (cpe-172-91-119-151.socal.res.rr.com [172.91.119.151]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 6BBB41600DB; Fri, 6 May 2022 02:25:25 -0700 (PDT) Message-ID: <804563bc-8ed8-9526-e2da-ab331d98e578@cs.ucla.edu> Date: Fri, 6 May 2022 02:25:24 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Content-Language: en-US To: Siddhesh Poyarekar , libc-alpha@sourceware.org Cc: fweimer@redhat.com, dickey@his.com, jakub@redhat.com, schwab@linux-m68k.org References: <20220505184348.3357550-1-siddhesh@sourceware.org> <20220505184348.3357550-3-siddhesh@sourceware.org> From: Paul Eggert Organization: UCLA Computer Science Department Subject: Re: [PATCH 2/2] wcrtomb: Make behavior POSIX compliant In-Reply-To: <20220505184348.3357550-3-siddhesh@sourceware.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 May 2022 09:25:28 -0000 On 5/5/22 11:43, Siddhesh Poyarekar wrote: > + else if (__glibc_unlikely (result > 1)) > + *((uint16_t *) s) = *((uint16_t *) buf); Shouldn't this be protected by "#if _STRING_ARCH_unaligned"? Also, unnecessary parens. But better yet, just call memcpy as the compiler will figure it out; see below. > - result = data.__outbuf - (unsigned char *) s; > + result = data.__outbuf - (unsigned char *) buf; > else > { > result = (size_t) -1; > __set_errno (EILSEQ); > } > > + if (result != (size_t) -1 && s != NULL) The 'result != (size_t) -1' can be omitted if you move that 'if' into the previous if's then-part. > + data.__outbufend = (unsigned char *) buf + MB_CUR_MAX; This'd be a bit faster (and less confusing) if we replace 'MB_CUR_MAX' with 'sizeof buf'. > + if (__glibc_unlikely (result > 2)) > + memcpy (s, buf, result); > + else if (__glibc_unlikely (result > 1)) > + *((uint16_t *) s) = *((uint16_t *) buf); > + else > + *s = *buf; If the likely path is result == 1, shouldn't that be checked first? Something like this: if (__glibc_likely (result < 2)) *s = *buf; else if (__glibc_likely (result == 2)) memcpy (s, buf, result); /* Help the compiler. */ else memcpy (s, buf, result);