Re: [xml] "double"s and schema validation
- From: "Andrew W. Nosenko" <andrew w nosenko gmail com>
- To: Dan Sommers <dan tombstonezero net>
- Cc: xml gnome org
- Subject: Re: [xml] "double"s and schema validation
- Date: Fri, 23 Jul 2010 05:48:39 +0300
On Fri, Jul 23, 2010 at 03:34, Dan Sommers <dan tombstonezero net> wrote:
On Thu, 22 Jul 2010 14:38:16 +0200, Csaba Raduly wrote:
Anyway, here's a revised version:
--- xmlschemastypes2.c 2010-07-21 13:17:12.229467800 +0200 +++
xmlschemastypes.c 2010-07-22 14:00:05.965759600 +0200 @@ -2392,6
+2392,8 @@
case XML_SCHEMAS_DOUBLE:{
const xmlChar *cur = value;
int neg = 0;
+ int digits_before = 0;
+ int digits_after = 0;
There's no need for two counters. Just use the same counter inside both
loops and check for that counter being zero (or non-zero) at the end
(then again, a sufficiently clever optimizer may already be doing that
for you).
No, optimizer cannot to do that because they aren't equivalent. Just
imagine that one int (e.g. digits_before) obtained value 1 and another
overflowed to -1. This scenario will produce "true" in
digits_before+digits_after==0 check. Now imagine the only one
counter. On the same imaginable data it will be overflowed to -2 and
check for zero will return "false".
But anyway, I see no needs in counters at all. Just because what you
need is just an boolean flag (zero vs. not zero, there were any digits
or not). Something like that:
int digits_found=0;
...
...
while ((*cur >= '0') && (*cur <= '9'))
{
++cur;
digits_found=1;
}
...
...
if (!digits_found)
{
/* handle error */
}
By the way it far simpler for optimizer and may be handled better by
it indeed without unsafe tricks and assumptions.
IMO, that fits the spirit of "a finite-length sequence of
decimal digits separated by a period" fairly well.
--
Andrew W. Nosenko <andrew w nosenko gmail com>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]