Re: [cc65] strcmp to empty string

From: Per Olofsson <magervalp1gmail.com>
Date: 2010-01-08 10:31:47
On Fri, Jan 8, 2010 at 8:37 AM, Shawn Jefferson <sjefferson@shaw.ca> wrote:
> It never occurred to me to not use strcmp(str, “”) == 0 to check for an
> empty string!  I just converted all these to checks of the first character
> of the ( string str[0] == ‘\0’ and str[0] != ‘\0’ ) and saved 341 bytes in
> my program, plus probably made it a bit faster to execute as well.

That sounds strange. This is what I get with 2.13.1:

; ---------------------------------------------------------------
; void __near__ comparenull (void)
; ---------------------------------------------------------------
;
; if (str[0] == '\0') {
;
	lda     _str
	sta     ptr1
	lda     _str+1
	sta     ptr1+1
	ldy     #$00
	lda     (ptr1),y
;
; isempty();
;
	jeq     _isempty
;
; }
;
	rts

; ---------------------------------------------------------------
; void __near__ compareptrnull (void)
; ---------------------------------------------------------------
;
; if (! *str) {
;
	lda     _str
	sta     ptr1
	lda     _str+1
	sta     ptr1+1
	ldy     #$00
	lda     (ptr1),y
;
; isempty();
;
	jeq     _isempty
;
; }
;
	rts

; ---------------------------------------------------------------
; void __near__ comparestrcmp (void)
; ---------------------------------------------------------------
;
; if (strcmp(str, "")) {
;
	lda     _str
	ldx     _str+1
	jsr     pushax
	lda     #<(L0001+9)
	ldx     #>(L0001+9)
	jsr     _strcmp
	stx     tmp1
	ora     tmp1
;
; isempty();
;
	jne     _isempty
;
; }
;
	rts

strcmp is larger (20 bytes vs 15) and quite a bit slower (roughly 2x).
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Fri Jan 8 10:32:32 2010

This archive was generated by hypermail 2.1.8 : 2010-01-08 10:32:35 CET