Blame gllib/streq.h

rpm-build 858c0f
/* Optimized string comparison.
rpm-build 858c0f
   Copyright (C) 2001-2002, 2007, 2009-2017 Free Software Foundation, Inc.
rpm-build 858c0f
rpm-build 858c0f
   This program is free software: you can redistribute it and/or modify it
rpm-build 858c0f
   under the terms of the GNU General Public License as published
rpm-build 858c0f
   by the Free Software Foundation; either version 3 of the License, or
rpm-build 858c0f
   (at your option) any later version.
rpm-build 858c0f
rpm-build 858c0f
   This program is distributed in the hope that it will be useful,
rpm-build 858c0f
   but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build 858c0f
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build 858c0f
   General Public License for more details.
rpm-build 858c0f
rpm-build 858c0f
   You should have received a copy of the GNU General Public License
rpm-build 858c0f
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
rpm-build 858c0f
rpm-build 858c0f
/* Written by Bruno Haible <bruno@clisp.org>.  */
rpm-build 858c0f
rpm-build 858c0f
#ifndef _GL_STREQ_H
rpm-build 858c0f
#define _GL_STREQ_H
rpm-build 858c0f
rpm-build 858c0f
#include <string.h>
rpm-build 858c0f
rpm-build 858c0f
/* STREQ_OPT allows to optimize string comparison with a small literal string.
rpm-build 858c0f
     STREQ_OPT (s, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
rpm-build 858c0f
   is semantically equivalent to
rpm-build 858c0f
     strcmp (s, "EUC-KR") == 0
rpm-build 858c0f
   just faster.  */
rpm-build 858c0f
rpm-build 858c0f
/* Help GCC to generate good code for string comparisons with
rpm-build 858c0f
   immediate strings. */
rpm-build 858c0f
#if defined (__GNUC__) && defined (__OPTIMIZE__)
rpm-build 858c0f
rpm-build 858c0f
static inline int
rpm-build 858c0f
streq9 (const char *s1, const char *s2)
rpm-build 858c0f
{
rpm-build 858c0f
  return strcmp (s1 + 9, s2 + 9) == 0;
rpm-build 858c0f
}
rpm-build 858c0f
rpm-build 858c0f
static inline int
rpm-build 858c0f
streq8 (const char *s1, const char *s2, char s28)
rpm-build 858c0f
{
rpm-build 858c0f
  if (s1[8] == s28)
rpm-build 858c0f
    {
rpm-build 858c0f
      if (s28 == 0)
rpm-build 858c0f
        return 1;
rpm-build 858c0f
      else
rpm-build 858c0f
        return streq9 (s1, s2);
rpm-build 858c0f
    }
rpm-build 858c0f
  else
rpm-build 858c0f
    return 0;
rpm-build 858c0f
}
rpm-build 858c0f
rpm-build 858c0f
static inline int
rpm-build 858c0f
streq7 (const char *s1, const char *s2, char s27, char s28)
rpm-build 858c0f
{
rpm-build 858c0f
  if (s1[7] == s27)
rpm-build 858c0f
    {
rpm-build 858c0f
      if (s27 == 0)
rpm-build 858c0f
        return 1;
rpm-build 858c0f
      else
rpm-build 858c0f
        return streq8 (s1, s2, s28);
rpm-build 858c0f
    }
rpm-build 858c0f
  else
rpm-build 858c0f
    return 0;
rpm-build 858c0f
}
rpm-build 858c0f
rpm-build 858c0f
static inline int
rpm-build 858c0f
streq6 (const char *s1, const char *s2, char s26, char s27, char s28)
rpm-build 858c0f
{
rpm-build 858c0f
  if (s1[6] == s26)
rpm-build 858c0f
    {
rpm-build 858c0f
      if (s26 == 0)
rpm-build 858c0f
        return 1;
rpm-build 858c0f
      else
rpm-build 858c0f
        return streq7 (s1, s2, s27, s28);
rpm-build 858c0f
    }
rpm-build 858c0f
  else
rpm-build 858c0f
    return 0;
rpm-build 858c0f
}
rpm-build 858c0f
rpm-build 858c0f
static inline int
rpm-build 858c0f
streq5 (const char *s1, const char *s2, char s25, char s26, char s27, char s28)
rpm-build 858c0f
{
rpm-build 858c0f
  if (s1[5] == s25)
rpm-build 858c0f
    {
rpm-build 858c0f
      if (s25 == 0)
rpm-build 858c0f
        return 1;
rpm-build 858c0f
      else
rpm-build 858c0f
        return streq6 (s1, s2, s26, s27, s28);
rpm-build 858c0f
    }
rpm-build 858c0f
  else
rpm-build 858c0f
    return 0;
rpm-build 858c0f
}
rpm-build 858c0f
rpm-build 858c0f
static inline int
rpm-build 858c0f
streq4 (const char *s1, const char *s2, char s24, char s25, char s26, char s27, char s28)
rpm-build 858c0f
{
rpm-build 858c0f
  if (s1[4] == s24)
rpm-build 858c0f
    {
rpm-build 858c0f
      if (s24 == 0)
rpm-build 858c0f
        return 1;
rpm-build 858c0f
      else
rpm-build 858c0f
        return streq5 (s1, s2, s25, s26, s27, s28);
rpm-build 858c0f
    }
rpm-build 858c0f
  else
rpm-build 858c0f
    return 0;
rpm-build 858c0f
}
rpm-build 858c0f
rpm-build 858c0f
static inline int
rpm-build 858c0f
streq3 (const char *s1, const char *s2, char s23, char s24, char s25, char s26, char s27, char s28)
rpm-build 858c0f
{
rpm-build 858c0f
  if (s1[3] == s23)
rpm-build 858c0f
    {
rpm-build 858c0f
      if (s23 == 0)
rpm-build 858c0f
        return 1;
rpm-build 858c0f
      else
rpm-build 858c0f
        return streq4 (s1, s2, s24, s25, s26, s27, s28);
rpm-build 858c0f
    }
rpm-build 858c0f
  else
rpm-build 858c0f
    return 0;
rpm-build 858c0f
}
rpm-build 858c0f
rpm-build 858c0f
static inline int
rpm-build 858c0f
streq2 (const char *s1, const char *s2, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
rpm-build 858c0f
{
rpm-build 858c0f
  if (s1[2] == s22)
rpm-build 858c0f
    {
rpm-build 858c0f
      if (s22 == 0)
rpm-build 858c0f
        return 1;
rpm-build 858c0f
      else
rpm-build 858c0f
        return streq3 (s1, s2, s23, s24, s25, s26, s27, s28);
rpm-build 858c0f
    }
rpm-build 858c0f
  else
rpm-build 858c0f
    return 0;
rpm-build 858c0f
}
rpm-build 858c0f
rpm-build 858c0f
static inline int
rpm-build 858c0f
streq1 (const char *s1, const char *s2, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
rpm-build 858c0f
{
rpm-build 858c0f
  if (s1[1] == s21)
rpm-build 858c0f
    {
rpm-build 858c0f
      if (s21 == 0)
rpm-build 858c0f
        return 1;
rpm-build 858c0f
      else
rpm-build 858c0f
        return streq2 (s1, s2, s22, s23, s24, s25, s26, s27, s28);
rpm-build 858c0f
    }
rpm-build 858c0f
  else
rpm-build 858c0f
    return 0;
rpm-build 858c0f
}
rpm-build 858c0f
rpm-build 858c0f
static inline int
rpm-build 858c0f
streq0 (const char *s1, const char *s2, char s20, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
rpm-build 858c0f
{
rpm-build 858c0f
  if (s1[0] == s20)
rpm-build 858c0f
    {
rpm-build 858c0f
      if (s20 == 0)
rpm-build 858c0f
        return 1;
rpm-build 858c0f
      else
rpm-build 858c0f
        return streq1 (s1, s2, s21, s22, s23, s24, s25, s26, s27, s28);
rpm-build 858c0f
    }
rpm-build 858c0f
  else
rpm-build 858c0f
    return 0;
rpm-build 858c0f
}
rpm-build 858c0f
rpm-build 858c0f
#define STREQ_OPT(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
rpm-build 858c0f
  streq0 (s1, s2, s20, s21, s22, s23, s24, s25, s26, s27, s28)
rpm-build 858c0f
rpm-build 858c0f
#else
rpm-build 858c0f
rpm-build 858c0f
#define STREQ_OPT(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
rpm-build 858c0f
  (strcmp (s1, s2) == 0)
rpm-build 858c0f
rpm-build 858c0f
#endif
rpm-build 858c0f
rpm-build 858c0f
#endif /* _GL_STREQ_H */