[vlc-devel] commit: Further optimize function (Antoine Cellerier )
git version control
git at videolan.org
Tue Sep 23 15:58:42 CEST 2008
vlc | branch: master | Antoine Cellerier <dionoea at videolan.org> | Tue Sep 23 16:01:37 2008 +0200| [423954f02d82aab7609883a25eba25fe20b73084] | committer: Antoine Cellerier
Further optimize function
we already know that the string starts with a &
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=423954f02d82aab7609883a25eba25fe20b73084
---
src/text/strings.c | 272 ++++++++++++++++++++++++++--------------------------
1 files changed, 137 insertions(+), 135 deletions(-)
diff --git a/src/text/strings.c b/src/text/strings.c
index ef67623..ff43403 100644
--- a/src/text/strings.c
+++ b/src/text/strings.c
@@ -239,129 +239,129 @@ char *encode_URI_component( const char *psz_url )
static const struct xml_entity_s
{
- char psz_entity[9];
+ char psz_entity[8];
uint8_t i_length;
char psz_char[4];
} p_xml_entities[] = {
/* Important: this list has to be in alphabetical order (psz_entity-wise) */
- { "Æ", 7, "Æ" },
- { "Á", 8, "Á" },
- { "Â", 7, "Â" },
- { "À", 8, "À" },
- { "Å", 7, "Å" },
- { "Ã", 8, "Ã" },
- { "Ä", 6, "Ä" },
- { "Ç", 8, "Ç" },
- { "‡", 8, "‡" },
- { "Ð", 5, "Ð" },
- { "É", 8, "É" },
- { "Ê", 7, "Ê" },
- { "È", 8, "È" },
- { "Ë", 6, "Ë" },
- { "Í", 8, "Í" },
- { "Î", 7, "Î" },
- { "Ì", 8, "Ì" },
- { "Ï", 6, "Ï" },
- { "Ñ", 8, "Ñ" },
- { "Œ", 7, "Œ" },
- { "Ó", 8, "Ó" },
- { "Ô", 7, "Ô" },
- { "Ò", 8, "Ò" },
- { "Ø", 8, "Ø" },
- { "Õ", 8, "Õ" },
- { "Ö", 6, "Ö" },
- { "Š", 8, "Š" },
- { "Þ", 7, "Þ" },
- { "Ú", 8, "Ú" },
- { "Û", 7, "Û" },
- { "Ù", 8, "Ù" },
- { "Ü", 6, "Ü" },
- { "Ý", 8, "Ý" },
- { "Ÿ", 6, "Ÿ" },
- { "á", 8, "á" },
- { "â", 7, "â" },
- { "´", 7, "´" },
- { "æ", 7, "æ" },
- { "à", 8, "à" },
- { "å", 7, "å" },
- { "ã", 8, "ã" },
- { "ä", 6, "ä" },
- { "„", 7, "„" },
- { "¦", 8, "¦" },
- { "ç", 8, "ç" },
- { "¸", 7, "¸" },
- { "¢", 6, "¢" },
- { "ˆ", 6, "ˆ" },
- { "©", 6, "©" },
- { "¤", 8, "¤" },
- { "†", 8, "†" },
- { "°", 5, "°" },
- { "÷", 8, "÷" },
- { "é", 8, "é" },
- { "ê", 7, "ê" },
- { "è", 8, "è" },
- { "ð", 5, "ð" },
- { "ë", 6, "ë" },
- { "€", 6, "€" },
- { "½", 8, "½" },
- { "¼", 8, "¼" },
- { "¾", 8, "¾" },
- { "…", 8, "…" },
- { "í", 8, "í" },
- { "î", 7, "î" },
- { "¡", 7, "¡" },
- { "ì", 8, "ì" },
- { "¿", 8, "¿" },
- { "ï", 6, "ï" },
- { "«", 7, "«" },
- { "“", 7, "“" },
- { "‹", 8, "‹" },
- { "‘", 7, "‘" },
- { "¯", 6, "¯" },
- { "—", 7, "—" },
- { "µ", 7, "µ" },
- { "·", 8, "·" },
- { "–", 7, "–" },
- { "¬", 5, "¬" },
- { "ñ", 8, "ñ" },
- { "ó", 8, "ó" },
- { "ô", 7, "ô" },
- { "œ", 7, "œ" },
- { "ò", 8, "ò" },
- { "ª", 6, "ª" },
- { "º", 6, "º" },
- { "ø", 8, "ø" },
- { "õ", 8, "õ" },
- { "ö", 6, "ö" },
- { "¶", 6, "¶" },
- { "‰", 8, "‰" },
- { "±", 8, "±" },
- { "£", 7, "£" },
- { "»", 7, "»" },
- { "”", 7, "”" },
- { "®", 5, "®" },
- { "›", 8, "›" },
- { "’", 7, "’" },
- { "‚", 7, "‚" },
- { "š", 8, "š" },
- { "§", 6, "§" },
- { "", 5, "" },
- { "¹", 6, "¹" },
- { "²", 6, "²" },
- { "³", 6, "³" },
- { "ß", 7, "ß" },
- { "þ", 7, "þ" },
- { "˜", 7, "˜" },
- { "×", 7, "×" },
- { "™", 7, "™" },
- { "ú", 8, "ú" },
- { "û", 7, "û" },
- { "ù", 8, "ù" },
- { "¨", 5, "¨" },
- { "ü", 6, "ü" },
- { "ý", 8, "ý" },
- { "¥", 5, "¥" },
- { "ÿ", 6, "ÿ" },
+ { "AElig;", 6, "Æ" },
+ { "Aacute;", 7, "Á" },
+ { "Acirc;", 6, "Â" },
+ { "Agrave;", 7, "À" },
+ { "Aring;", 6, "Å" },
+ { "Atilde;", 7, "Ã" },
+ { "Auml;", 5, "Ä" },
+ { "Ccedil;", 7, "Ç" },
+ { "Dagger;", 7, "‡" },
+ { "ETH;", 4, "Ð" },
+ { "Eacute;", 7, "É" },
+ { "Ecirc;", 6, "Ê" },
+ { "Egrave;", 7, "È" },
+ { "Euml;", 5, "Ë" },
+ { "Iacute;", 7, "Í" },
+ { "Icirc;", 6, "Î" },
+ { "Igrave;", 7, "Ì" },
+ { "Iuml;", 5, "Ï" },
+ { "Ntilde;", 7, "Ñ" },
+ { "OElig;", 6, "Œ" },
+ { "Oacute;", 7, "Ó" },
+ { "Ocirc;", 6, "Ô" },
+ { "Ograve;", 7, "Ò" },
+ { "Oslash;", 7, "Ø" },
+ { "Otilde;", 7, "Õ" },
+ { "Ouml;", 5, "Ö" },
+ { "Scaron;", 7, "Š" },
+ { "THORN;", 6, "Þ" },
+ { "Uacute;", 7, "Ú" },
+ { "Ucirc;", 6, "Û" },
+ { "Ugrave;", 7, "Ù" },
+ { "Uuml;", 5, "Ü" },
+ { "Yacute;", 7, "Ý" },
+ { "Yuml;", 5, "Ÿ" },
+ { "aacute;", 7, "á" },
+ { "acirc;", 6, "â" },
+ { "acute;", 6, "´" },
+ { "aelig;", 6, "æ" },
+ { "agrave;", 7, "à" },
+ { "aring;", 6, "å" },
+ { "atilde;", 7, "ã" },
+ { "auml;", 5, "ä" },
+ { "bdquo;", 6, "„" },
+ { "brvbar;", 7, "¦" },
+ { "ccedil;", 7, "ç" },
+ { "cedil;", 6, "¸" },
+ { "cent;", 5, "¢" },
+ { "circ;", 5, "ˆ" },
+ { "copy;", 5, "©" },
+ { "curren;", 7, "¤" },
+ { "dagger;", 7, "†" },
+ { "deg;", 4, "°" },
+ { "divide;", 7, "÷" },
+ { "eacute;", 7, "é" },
+ { "ecirc;", 6, "ê" },
+ { "egrave;", 7, "è" },
+ { "eth;", 4, "ð" },
+ { "euml;", 5, "ë" },
+ { "euro;", 5, "€" },
+ { "frac12;", 7, "½" },
+ { "frac14;", 7, "¼" },
+ { "frac34;", 7, "¾" },
+ { "hellip;", 7, "…" },
+ { "iacute;", 7, "í" },
+ { "icirc;", 6, "î" },
+ { "iexcl;", 6, "¡" },
+ { "igrave;", 7, "ì" },
+ { "iquest;", 7, "¿" },
+ { "iuml;", 5, "ï" },
+ { "laquo;", 6, "«" },
+ { "ldquo;", 6, "“" },
+ { "lsaquo;", 7, "‹" },
+ { "lsquo;", 6, "‘" },
+ { "macr;", 5, "¯" },
+ { "mdash;", 6, "—" },
+ { "micro;", 6, "µ" },
+ { "middot;", 7, "·" },
+ { "ndash;", 6, "–" },
+ { "not;", 4, "¬" },
+ { "ntilde;", 7, "ñ" },
+ { "oacute;", 7, "ó" },
+ { "ocirc;", 6, "ô" },
+ { "oelig;", 6, "œ" },
+ { "ograve;", 7, "ò" },
+ { "ordf;", 5, "ª" },
+ { "ordm;", 5, "º" },
+ { "oslash;", 7, "ø" },
+ { "otilde;", 7, "õ" },
+ { "ouml;", 5, "ö" },
+ { "para;", 5, "¶" },
+ { "permil;", 7, "‰" },
+ { "plusmn;", 7, "±" },
+ { "pound;", 6, "£" },
+ { "raquo;", 6, "»" },
+ { "rdquo;", 6, "”" },
+ { "reg;", 4, "®" },
+ { "rsaquo;", 7, "›" },
+ { "rsquo;", 6, "’" },
+ { "sbquo;", 6, "‚" },
+ { "scaron;", 7, "š" },
+ { "sect;", 5, "§" },
+ { "shy;", 4, "" },
+ { "sup1;", 5, "¹" },
+ { "sup2;", 5, "²" },
+ { "sup3;", 5, "³" },
+ { "szlig;", 6, "ß" },
+ { "thorn;", 6, "þ" },
+ { "tilde;", 6, "˜" },
+ { "times;", 6, "×" },
+ { "trade;", 6, "™" },
+ { "uacute;", 7, "ú" },
+ { "ucirc;", 6, "û" },
+ { "ugrave;", 7, "ù" },
+ { "uml;", 4, "¨" },
+ { "uuml;", 5, "ü" },
+ { "yacute;", 7, "ý" },
+ { "yen;", 4, "¥" },
+ { "yuml;", 5, "ÿ" },
};
/**
@@ -376,19 +376,20 @@ void resolve_xml_special_chars( char *psz_value )
{
if( *psz_value == '&' )
{
-#define TRY_CHAR( src, len, dst ) \
- if( !strncmp( psz_value, src, len ) ) \
- { \
- *p_pos = dst; \
- psz_value += len; \
+ char *psz_value1 = psz_value + 1;
+#define TRY_CHAR( src, len, dst ) \
+ if( !strncmp( psz_value1, src, len ) ) \
+ { \
+ *p_pos = dst; \
+ psz_value += len; \
}
- TRY_CHAR( "<", 4, '<' )
- else TRY_CHAR( "&", 5, '&' )
- else TRY_CHAR( "'", 6, '\'' )
- else TRY_CHAR( ">", 4, '>' )
- else TRY_CHAR( """, 6, '"' )
+ TRY_CHAR( "lt;", 4, '<' )
+ else TRY_CHAR( "amp;", 5, '&' )
+ else TRY_CHAR( "apos;", 6, '\'' )
+ else TRY_CHAR( "gt;", 4, '>' )
+ else TRY_CHAR( "quot;", 6, '"' )
#undef TRY_CHAR
- else if( psz_value[1] == '#' )
+ else if( *psz_value1 == '#' )
{
char *psz_end;
int i = strtol( psz_value+2, &psz_end, 10 );
@@ -427,14 +428,15 @@ void resolve_xml_special_chars( char *psz_value )
if( i >= i_entities )
cmp = -1;
else
- cmp = strncmp( psz_value, p_xml_entities[i].psz_entity,
+ cmp = strncmp( psz_value1, /* Skip the & */
+ p_xml_entities[i].psz_entity,
p_xml_entities[i].i_length );
if( cmp == 0 )
{
- strncpy( p_pos, p_xml_entities[i].psz_char,
- p_xml_entities[i].i_length );
- p_pos += strlen( p_xml_entities[i].psz_char ) - 1;
- psz_value += p_xml_entities[i].i_length;
+ size_t i_len = strlen( p_xml_entities[i].psz_char );
+ strncpy( p_pos, p_xml_entities[i].psz_char, i_len );
+ p_pos += i_len - 1;
+ psz_value += p_xml_entities[i].i_length+1;
break;
}
else if( cmp < 0 )
More information about the vlc-devel
mailing list