strtosz() more cleanups
cover strtosz() more cleanups
From: Jes Sorensen <[email protected]>
Another two cleanups to strtosz() suggested by Alex Williamson.
I had reversed the use of the names of the return arguments to modf(), and use the STRTOSZ_DESUFFIX_ macros in the switch() statement.
Cheers,
Jes
Jes Sorensen (2):
strtosz(): Fix name confusion in use of modf() strtosz(): Use suffix macros in switch() statement
cutils.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)
Signature · 1 line
1.7.3.4
PATCH 1/2 strtosz(): Fix name confusion in use of modf()
From: Jes Sorensen <[email protected]>
--- cutils.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
cutils.c +2 -2
@@ -304,8 +304,8 @@ ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix)if (isnan (val) || endptr == nptr || errno !=0 ) { goto fail; } - integral =modf (val, &fraction); -if (integral !=0 ) { + fraction =modf (val, &integral); +if (fraction !=0 ) { mul_required =1 ; }/*
Signature · 1 line
1.7.3.4
PATCH 2/2 strtosz(): Use suffix macros in switch() statement
In reply to [email protected]From: Jes Sorensen <[email protected]>
--- cutils.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
cutils.c +5 -5
@@ -324,26 +324,26 @@ ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) } }switch (toupper (d)) { -case 'B' : +case STRTOSZ_DEFSUFFIX_B : mul =1 ;if (mul_required) { goto fail; }break ; -case 'K' : +case STRTOSZ_DEFSUFFIX_KB : mul =1 <<10 ;break ;case 0 :if (mul_required) { goto fail; } -case 'M' : +case STRTOSZ_DEFSUFFIX_MB : mul =1ULL <<20 ;break ; -case 'G' : +case STRTOSZ_DEFSUFFIX_GB : mul =1ULL <<30 ;break ; -case 'T' : +case STRTOSZ_DEFSUFFIX_TB : mul =1ULL <<40 ;break ;default :
Signature · 1 line
1.7.3.4
Re: [Qemu-devel] [PATCH 2/2] strtosz(): Use suffix macros in switch() statement
Quoted 33 lines · [email protected] writes:
From: Jes Sorensen <[email protected]>
Signed-off-by Jes Sorensen <[email protected]>--- cutils.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)cutils.c +3
-3@@ -324,26 +324,26 @@ ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) } }switch (toupper (d)) { -case 'B' : +case STRTOSZ_DEFSUFFIX_B : mul =1 ;if (mul_required) { goto fail; }break ; -case 'K' : +case STRTOSZ_DEFSUFFIX_KB : mul =1 <<10 ;break ;case 0 :if (mul_required) { goto fail; } -case 'M' : +case STRTOSZ_DEFSUFFIX_MB : mul =1ULL <<20 ;
cutils.c ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) · line 349
Quoted 10 lines
cutils.c +2
-2break ; -case 'G' : +case STRTOSZ_DEFSUFFIX_GB : mul =1ULL <<30 ;break ; -case 'T' : +case STRTOSZ_DEFSUFFIX_TB : mul =1ULL <<40 ;break ;default :
And this improves what? Certainly not clarity.
In my opinion, the STRTOSZ_DEFSUFFIX_TB are useless chaff. Chacun à son goût.
Re: [Qemu-devel] [PATCH 2/2] strtosz(): Use suffix macros in switch() statement
Quoted 39 lines · Markus Armbruster
Quoted 26 lines
cutils.c +3
-3@@ -324,26 +324,26 @@ ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) } }switch (toupper (d)) { -case 'B' : +case STRTOSZ_DEFSUFFIX_B : mul =1 ;if (mul_required) { goto fail; }break ; -case 'K' : +case STRTOSZ_DEFSUFFIX_KB : mul =1 <<10 ;break ;case 0 :if (mul_required) { goto fail; } -case 'M' : +case STRTOSZ_DEFSUFFIX_MB : mul =1ULL <<20 ;cutils.c ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) · line 349
Quoted 10 lines
cutils.c +2
-2break ; -case 'G' : +case STRTOSZ_DEFSUFFIX_GB : mul =1ULL <<30 ;break ; -case 'T' : +case STRTOSZ_DEFSUFFIX_TB : mul =1ULL <<40 ;break ;default :And this improves what? Certainly not clarity.
Quoted 2 lines
In my opinion, the
STRTOSZ_DEFSUFFIX_TBare useless chaff. Chacun à son goût.
It cuts out lines of code, which is good, and using the macros means the user is less likely to make a type and use a wrong character.
It's a taste issue though, I agree!
Cheers,
Jes
Re: [Qemu-devel] [PATCH 2/2] strtosz(): Use suffix macros in switch() statement
In reply to Markus ArmbrusterQuoted 48 lines · Markus Armbruster
Quoted 33 lines · [email protected] writes:
From: Jes Sorensen <[email protected]>
Signed-off-by Jes Sorensen <[email protected]>--- cutils.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)cutils.c +3
-3@@ -324,26 +324,26 @@ ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) } }switch (toupper (d)) { -case 'B' : +case STRTOSZ_DEFSUFFIX_B : mul =1 ;if (mul_required) { goto fail; }break ; -case 'K' : +case STRTOSZ_DEFSUFFIX_KB : mul =1 <<10 ;break ;case 0 :if (mul_required) { goto fail; } -case 'M' : +case STRTOSZ_DEFSUFFIX_MB : mul =1ULL <<20 ;cutils.c ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) · line 349
Quoted 10 lines
cutils.c +2
-2break ; -case 'G' : +case STRTOSZ_DEFSUFFIX_GB : mul =1ULL <<30 ;break ; -case 'T' : +case STRTOSZ_DEFSUFFIX_TB : mul =1ULL <<40 ;break ;default :And this improves what? Certainly not clarity.
Quoted 2 lines
In my opinion, the
STRTOSZ_DEFSUFFIX_TBare useless chaff. Chacun à son goût.
<shrug> I prefer it. Better than having 'B'/'K'/'M'/'G'/'T' sprinkled throughout the code. Easier to search for, easier to update, more consistent.
Alex
Re: [Qemu-devel] [PATCH 2/2] strtosz(): Use suffix macros in switch() statement
In reply to Markus ArmbrusterQuoted 49 lines · Markus Armbruster
Quoted 34 lines · [email protected] writes:
From: Jes Sorensen<[email protected]>
Signed-off-by Jes Sorensen<[email protected]>--- cutils.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)cutils.c +3
-3@@ -324,26 +324,26 @@ ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) } }switch (toupper (d)) { -case 'B' : +case STRTOSZ_DEFSUFFIX_B : mul =1 ;if (mul_required) { goto fail; }break ; -case 'K' : +case STRTOSZ_DEFSUFFIX_KB : mul =1 <<10 ;break ;case 0 :if (mul_required) { goto fail; } -case 'M' : +case STRTOSZ_DEFSUFFIX_MB : mul =1ULL <<20 ;cutils.c ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) · line 349
Quoted 10 lines
cutils.c +2
-2break ; -case 'G' : +case STRTOSZ_DEFSUFFIX_GB : mul =1ULL <<30 ;break ; -case 'T' : +case STRTOSZ_DEFSUFFIX_TB : mul =1ULL <<40 ;break ;default :And this improves what? Certainly not clarity.
Quoted 3 lines
In my opinion, the
STRTOSZ_DEFSUFFIX_TBare useless chaff. Chacun à son goût.
Yeah, I have to agree. I'm not of the literals are evil camp.
BTW, a useful change would be to accept both upper and lower case letters.
Regards,
Anthony Liguori
Re: [Qemu-devel] [PATCH 2/2] strtosz(): Use suffix macros in switch() statement
Quoted 11 lines · Anthony Liguori
Quoted 10 lines · Markus Armbruster
Quoted 7 lines · [email protected] writes:
From: Jes Sorensen<[email protected]>
Signed-off-by Jes Sorensen<[email protected]>--- cutils.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
Quoted 9 lines
Quoted 9 lines
cutils.c ssize_t strtosz_suffix(const char *nptr, char · line 327
Quoted 9 lines
cutils.c +0
-0@@ -324,26 +324,26 @@ ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) } }switch (toupper (d)) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 10 lines
Quoted 6 lines
Quoted 1 line
And this improves what? Certainly not clarity.
In my opinion, the
STRTOSZ_DEFSUFFIX_TBare useless chaff. Chacun à son goût.Yeah, I have to agree. I'm not of the literals are evil camp.
BTW, a useful change would be to accept both upper and lower case letters.
It already supports both, it's handle in the toupper() call.
Cheers,
Jes
Re: [Qemu-devel] [PATCH 2/2] strtosz(): Use suffix macros in switch() statement
In reply to Anthony LiguoriQuoted 6 lines · Anthony Liguori
Quoted 5 lines
cutils.c ssize_t strtosz_suffix(const char *nptr, char · line 327
Quoted 5 lines
cutils.c +0
-0@@ -324,26 +324,26 @@ ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) } }switch (toupper (d)) {BTW, a useful change would be to accept both upper and lower case letters.
And it does, via the toupper() added earlier in the series (and which has separately been pointed out that using qemu_toupper() might be nicer).
Signature · 2 lines
Eric Blake [email protected] +1-801-349-2682 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 2/2] strtosz(): Use suffix macros in switch() statement
Quoted 10 lines · Eric Blake
Quoted 8 lines · Anthony Liguori
Quoted 6 lines
cutils.c ssize_t strtosz_suffix(const char *nptr, char · line 328
Quoted 6 lines
cutils.c +0
-0@@ -324,26 +324,26 @@ ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) } }switch (toupper (d)) {BTW, a useful change would be to accept both upper and lower case letters.
Quoted 3 lines
And it does, via the
toupper()added earlier in the series (and which has separately been pointed out that usingqemu_toupper()might be nicer).
Ok. Just taking the different case labels would be nicer IMHO.
Regards,
Anthony Liguori
Re: [Qemu-devel] [PATCH 2/2] strtosz(): Use suffix macros in switch() statement
Quoted 12 lines · Anthony Liguori
Quoted 11 lines · Eric Blake
Quoted 9 lines · Anthony Liguori
Quoted 6 lines
cutils.c ssize_t strtosz_suffix(const char *nptr, char · line 328
Quoted 6 lines
cutils.c +0
-0@@ -324,26 +324,26 @@ ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) } }switch (toupper (d)) {BTW, a useful change would be to accept both upper and lower case letters.
Quoted 6 lines
Quoted 4 lines
And it does, via the
toupper()added earlier in the series (and which has separately been pointed out that usingqemu_toupper()might be nicer).Ok. Just taking the different case labels would be nicer IMHO.
The old code did that, but I was suggested to do it this way, which I think is cleaner too. Fewer lines of code are easier to read.
Cheers,
Jes
Re: [Qemu-devel] [PATCH 2/2] strtosz(): Use suffix macros in switch() statement
Quoted 23 lines · Jes Sorensen
Quoted 21 lines · Anthony Liguori
Quoted 19 lines · Eric Blake
Quoted 11 lines · Anthony Liguori
Quoted 7 lines
cutils.c ssize_t strtosz_suffix(const char *nptr, char · line 329
Quoted 7 lines
cutils.c +0
-0@@ -324,26 +324,26 @@ ssize_t strtosz_suffix(const char *nptr, char **end, const char default_suffix) } }switch (toupper (d)) {BTW, a useful change would be to accept both upper and lower case letters.
And it does, via the
toupper()added earlier in the series (and which has separately been pointed out that usingqemu_toupper()might be nicer).
Quoted 5 lines
Quoted 2 lines
Ok. Just taking the different case labels would be nicer IMHO.
The old code did that, but I was suggested to do it this way, which I think is cleaner too. Fewer lines of code are easier to read.
toupper() is based on locale so it's not consistent.
Regards,
Anthony Liguori
Quoted 3 lines
Cheers,
Jes
Re: [Qemu-devel] [PATCH 2/2] strtosz(): Use suffix macros in switch() statement
Quoted 7 lines · Anthony Liguori
Quoted 6 lines · Jes Sorensen
Quoted 5 lines · Anthony Liguori
Quoted 4 lines · Eric Blake
And it does, via the
toupper()added earlier in the series (and which has separately been pointed out that usingqemu_toupper()might be nicer).
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
Ok. Just taking the different case labels would be nicer IMHO.
The old code did that, but I was suggested to do it this way, which I think is cleaner too. Fewer lines of code are easier to read.
toupper()is based on locale so it's not consistent.
If you can show me an actually used locale where the toupper() on k/m/g/t doesn't result in K/M/G/T then I guess there's a case. Otherwise I don't really see this being a real point.
I think we are hitting the point where it's about who's taste is better, and not about the actual code in this discussion.
One point in favor of the patch is this:
Without the patch:
jes@red-feather qemu]$ size cutils.o
text data bss dec hex filename
4212 0 0 4212 1074 cutils.o
With patch:
[jes@red-feather qemu]$ size cutils.o
text data bss dec hex filename
4196 0 0 4196 1064 cutils.o
IMHO it makes the code easier to read, but beyond that there isn't much. If people are strongly against it, I'll just drop the patch. It's not worth our time arguing over this level of detail. Otherwise I'd like to see it applied.
Cheers,
Jes
Quoted 11 lines · On Mon, 2011-01-17 at 18:12 +0100, [email protected] wrote:
From: Jes Sorensen <[email protected]>
Another two cleanups to
strtosz()suggested by Alex Williamson.I had reversed the use of the names of the return arguments to
modf(), and use theSTRTOSZ_DESUFFIX_macros in theswitch()statement.Cheers,
Jes
Quoted 7 lines
Jes Sorensen (2):
strtosz(): Fix name confusion in use ofmodf()strtosz(): Use suffix macros inswitch()statementcutils.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)