Date: Tue, 21 Jul 1998 11:22:49 +0300 (IDT) From: Eli Zaretskii To: Mariano Alvarez Fernández cc: djgpp AT delorie DOT com Subject: Re: About DJGPP v2.02, more results In-Reply-To: <35B38619.4E02@teleline.es> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Content-Transfer-Encoding: 8bit Precedence: bulk On Mon, 20 Jul 1998, Mariano Alvarez Fernández wrote: > > These entries seem to imply that you call strlen for each call to > > strcpy/strncpy. It would be faster to call memcpy/memmove instead, > > since once you know the length of a string, there's no reason to use > > the string-copy functions (which are slower because they look for the > > terminating null character). > > It's the dbf format too. In dbf char strings are blank filled, I use > null terminated strings internally, strcopnb do the input conversion. > > int strcopnb( char *dest, char *org, int max ) > { > int i; > > strncpy( dest,org,max ); > dest[max] = '\0'; > max = strlen( dest ); > for( i=max-1; i >= 0 && dest[i] == ' '; i-- ); > dest[i+1] = '\0'; > return 0; > } I think this should be faster: int strcopnb( char *dest, char *org, int max ) { int i; memcpy( dest,org,max ); dest[max] = '\0'; /* max = strlen( dest ); redundant: we just put '\0' at dest[max] */ for( i=max-1; i >= 0 && dest[i] == ' '; i-- ); dest[i+1] = '\0'; return 0; } This thread is quickly degenerating into a C optimization class ;-).