forked from qt-creator/qt-creator
		
	preprocessor: save cycles by using ByteArrayRef
Change-Id: I339696763b045ef1bda17dd55746738ef4ddbb67 Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
		| @@ -64,7 +64,7 @@ public: | ||||
|     virtual void macroAdded(const Macro &) {} | ||||
|  | ||||
|     virtual void passedMacroDefinitionCheck(unsigned, const Macro &) {} | ||||
|     virtual void failedMacroDefinitionCheck(unsigned, const QByteArray &) {} | ||||
|     virtual void failedMacroDefinitionCheck(unsigned, const Internal::ByteArrayRef &) {} | ||||
|  | ||||
|     virtual void startExpandingMacro(unsigned, | ||||
|                                      const Macro &, | ||||
|   | ||||
| @@ -22,6 +22,11 @@ public: | ||||
|         , m_length(ref->length()) | ||||
|     {} | ||||
|  | ||||
|     ByteArrayRef(const char *start, int length) | ||||
|         : m_start(start) | ||||
|         , m_length(length) | ||||
|     {} | ||||
|  | ||||
|     ByteArrayRef(const QByteArray *ref, int offset, int length) | ||||
|         : m_start(ref->constData() + offset) | ||||
|         , m_length(length) | ||||
|   | ||||
| @@ -43,6 +43,7 @@ QT_END_NAMESPACE | ||||
|  | ||||
| namespace CPlusPlus { | ||||
|  | ||||
| namespace Internal { class ByteArrayRef; } | ||||
| class Macro; | ||||
|  | ||||
| class CPLUSPLUS_EXPORT MacroArgumentReference | ||||
| @@ -80,7 +81,7 @@ public: | ||||
|   virtual void macroAdded(const Macro ¯o) = 0; | ||||
|  | ||||
|   virtual void passedMacroDefinitionCheck(unsigned offset, const Macro ¯o) = 0; | ||||
|   virtual void failedMacroDefinitionCheck(unsigned offset, const QByteArray &name) = 0; | ||||
|   virtual void failedMacroDefinitionCheck(unsigned offset, const Internal::ByteArrayRef &name) = 0; | ||||
|  | ||||
|   virtual void startExpandingMacro(unsigned offset, | ||||
|                                    const Macro ¯o, | ||||
|   | ||||
| @@ -210,7 +210,7 @@ inline bool isValidToken(const PPToken &tk) | ||||
|     return tk.isNot(T_EOF_SYMBOL) && (! tk.newline() || tk.joined()); | ||||
| } | ||||
|  | ||||
| Macro *macroDefinition(const QByteArray &name, unsigned offset, Environment *env, Client *client) | ||||
| Macro *macroDefinition(const ByteArrayRef &name, unsigned offset, Environment *env, Client *client) | ||||
| { | ||||
|     Macro *m = env->resolve(name); | ||||
|     if (client) { | ||||
| @@ -306,7 +306,7 @@ protected: | ||||
|     { | ||||
|         if ((*_lex)->isNot(T_IDENTIFIER)) | ||||
|             return false; | ||||
|         const QByteArray spell = tokenSpell(); | ||||
|         const ByteArrayRef spell = tokenSpell(); | ||||
|         if (spell.size() != 7) | ||||
|             return false; | ||||
|         return spell == "defined"; | ||||
| @@ -322,11 +322,9 @@ protected: | ||||
|         return (*_lex)->f.length; | ||||
|     } | ||||
|  | ||||
|     QByteArray tokenSpell() const | ||||
|     ByteArrayRef tokenSpell() const | ||||
|     { | ||||
|         const QByteArray text = QByteArray::fromRawData(source.constData() + (*_lex)->offset, | ||||
|                                                         (*_lex)->f.length); | ||||
|         return text; | ||||
|         return ByteArrayRef(tokenPosition(), tokenLength()); | ||||
|     } | ||||
|  | ||||
|     inline void process_expression() | ||||
| @@ -1430,7 +1428,7 @@ void Preprocessor::handleIfDefDirective(bool checkUndefined, PPToken *tk) | ||||
|     if (tk->is(T_IDENTIFIER)) { | ||||
|         bool value = false; | ||||
|         const ByteArrayRef macroName = tk->asByteArrayRef(); | ||||
|         if (Macro *macro = macroDefinition(macroName.toByteArray(), tk->offset, m_env, m_client)) { | ||||
|         if (Macro *macro = macroDefinition(macroName, tk->offset, m_env, m_client)) { | ||||
|             value = true; | ||||
|  | ||||
|             // the macro is a feature constraint(e.g. QT_NO_XXX) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user