Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:10408 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6545 invoked by uid 1010); 12 Jun 2004 14:28:30 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 6447 invoked by uid 1007); 12 Jun 2004 14:28:30 -0000 To: internals@lists.php.net References: Message-ID: Date: Sat, 12 Jun 2004 17:27:45 +0300 Organization: none Content-Type: text/plain; format=flowed; delsp=yes; charset=koi8-r MIME-Version: 1.0 Content-Transfer-Encoding: 8bit User-Agent: Opera M2/7.50 (Win32, build 3778) X-Posted-By: 217.23.116.150 Subject: Re: [PHP-DEV] str_repeat() patch From: valyala@tut.by ("Alexander Valyalkin") On Fri, 11 Jun 2004 17:00:03 +0200 (CEST), Derick Rethans wrote: > On Fri, 11 Jun 2004, Alexander Valyalkin wrote: > >> >> Read it: >> void *memmove(void *s1, const void *s2, size_t n); >> If s1 and s2 overlap, all bytes are copied in a preserving manner >> (unlike >> memcpy()) >> >> And anwer the question: are s1 and s2 overlap in the str_repeat() ? >> Why don't use memcpy() instead of memmove() ? > > Because it's slower and we're copying to newly allocated memory anyway > so things CAN not overlap. Also, your patch is the wrong way around. > Mybe I'm mistaken, but I think, that memmove() looks like that (without any error checks): void *memmove(void *dst, void *src, size_t len) { /* check overlapping of src & dst */ size_t distance = (char *)dst > (char *)src ? (char *)dst - (char *)src : (char *)src - (char *)dst; if (distance < len) { /* overlap. Use temporary buffer & memcpy(). Here could be used byte-to-byte copying or any oher tricks */ char *tmp = malloc(len); memcpy(tmp, src, len); memcpy(dst, tmp, len); free(tmp); } else { /* not overlap. Use memcpy() */ memcpy(dst, src, len); } return dst; } Are you still think that memcpy() is slower than memmove() ? I would tell that memcpy() at least not more slowly than memmove(). -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/