strange code in gscanner.c



   Hi,

 While reading the code of gscanner.c (glib-2.0.0), I've found this
(line 1675 and below):
      if (token == G_TOKEN_IDENTIFIER &&
          config->scan_identifier_NULL &&
          strlen (value.v_identifier) == 4)
        {
          gchar *null_upper = "NULL";
          gchar *null_lower = "null";

          if (scanner->config->case_sensitive)
            {
              if (value.v_identifier[0] == null_upper[0] &&
                  value.v_identifier[1] == null_upper[1] &&
                  value.v_identifier[2] == null_upper[2] &&
                  value.v_identifier[3] == null_upper[3])
                token = G_TOKEN_IDENTIFIER_NULL;
            }
          else
            {
              if ((value.v_identifier[0] == null_upper[0] ||
                   value.v_identifier[0] == null_lower[0]) &&
                  (value.v_identifier[1] == null_upper[1] ||
                   value.v_identifier[1] == null_lower[1]) &&
                  (value.v_identifier[2] == null_upper[2] ||
                   value.v_identifier[2] == null_lower[2]) &&
                  (value.v_identifier[3] == null_upper[3] ||
                   value.v_identifier[3] == null_lower[3]))
                token = G_TOKEN_IDENTIFIER_NULL;
            }
        }

Is there any reason not to write it in this much simpler way:
      if (token == G_TOKEN_IDENTIFIER &&
          config->scan_identifier_NULL &&
          strlen (value.v_identifier) == 4)
        {
          if (scanner->config->case_sensitive)
            {
              if (strcmp (value.v_identifier, "NULL") == 0)
                token = G_TOKEN_IDENTIFIER_NULL;
            }
          else
            {
              if (g_strcasecmp (value.v_identifier, NULL) == 0)
                token = G_TOKEN_IDENTIFIER_NULL;
            }
        }

   I think the later in much easier to read.

   OK to commit?

    Regards,

           DindinX


-- 
David dindinx org



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