From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20690 invoked by alias); 10 Sep 2014 18:02:03 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 20680 invoked by uid 89); 10 Sep 2014 18:02:03 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL,BAYES_00,RDNS_DYNAMIC,TVD_RCVD_IP autolearn=no version=3.3.2 X-HELO: brightrain.aerifal.cx Date: Wed, 10 Sep 2014 18:02:00 -0000 From: Rich Felker To: Florian Weimer Cc: Wilco Dijkstra , azanella@linux.vnet.ibm.com, libc-alpha@sourceware.org Subject: Re: [PATCH] Improve performance of strncpy Message-ID: <20140910180144.GK23797@brightrain.aerifal.cx> References: <001301cfcd0a$f0b62670$d2227350$@com> <54108BB0.90902@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <54108BB0.90902@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-SW-Source: 2014-09/txt/msg00195.txt.bz2 On Wed, Sep 10, 2014 at 07:34:40PM +0200, Florian Weimer wrote: > On 09/10/2014 05:21 PM, Wilco Dijkstra wrote: > >Yes, you're right, I timed it and there is actually little difference, while > >the code is now even simpler. New version below (not attaching results in bad > >characters due to various mail servers changing line endings). > > > >OK for commit? > > I think you could simplify it down to strnlen, memcpy, and memset. I don't think that's an improvement, at least not in the general case. It involves iterating twice over the source string, which for long strings could mean blowing the whole cache twice and fetching from main memory twice. There's a good reason that string operations are usually implemented to perform the copy and length computation together in a single pass. Rich