RE: [PATCH] Add a basic date format check to DIDL-Lite parser (v3)



On Mi, 2011-07-06 at 16:57 +0300, Santakivi Topi wrote:
> ---
>  libgupnp-av/gupnp-didl-lite-parser.c |   61 +++++++++++++++++++++++++--------
>  libgupnp-av/gupnp-didl-lite-parser.h |    4 ++-
>  2 files changed, 49 insertions(+), 16 deletions(-)

Actually the DFA approach we discussed on IRC would be less intrusive:

int state = 0;
char *ptr = date;
while (*ptr)
{
    if (state == 4 || state == 7) {
        if (*ptr != '-') {
            break;
        }
    } else {
        if (!isdigit(*ptr)) {
            break;
        }

    state++;
    ptr++;
    if (state == 10)
        return TRUE;
}

return FALSE;

And, just for reference:

For 10000 iterations checking a date like "1978-13-07", I get (on my
PC):

** (process:29594): DEBUG: DFA Matching took: 0.000909
** (process:29594): DEBUG: GRegexx Matching took: 0.008746

On arm:

dfa-date-check[9459]: GLIB DEBUG default - Matching took: 0.001648
dfa-date-check[9459]: GLIB DEBUG default - Matching took: 0.097443

So DFA time doubles while GRegex is times 10. :(

Still, as said before, this the sum of all 10000 executions, so for one
check it doesn't really matter, but the overall result is interesting
nevertheless.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]