Explorar el Código

Simplify ParseName

Only the first char needs to be checked with IsNameStartChar, so check
it before the loop.
JayXon hace 11 años
padre
commit
ee525dba4d
Se han modificado 1 ficheros con 7 adiciones y 7 borrados
  1. 7 7
      tinyxml2.cpp

+ 7 - 7
tinyxml2.cpp

@@ -140,18 +140,18 @@ char* StrPair::ParseName( char* p )
     if ( !p || !(*p) ) {
         return 0;
     }
+    if ( !XMLUtil::IsNameStartChar( *p ) ) {
+        return 0;
+    }
 
     char* const start = p;
-
-    while( *p && ( p == start ? XMLUtil::IsNameStartChar( *p ) : XMLUtil::IsNameChar( *p ) )) {
+    ++p;
+    while ( *p && XMLUtil::IsNameChar( *p ) ) {
         ++p;
     }
 
-    if ( p > start ) {
-        Set( start, p, 0 );
-        return p;
-    }
-    return 0;
+    Set( start, p, 0 );
+    return p;
 }