mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 12:00:17 +02:00
ZLUnicodeUtil::toLower() optimization: do not call java method for ascii strings
This commit is contained in:
parent
9d2080af7f
commit
2e5c911d43
2 changed files with 20 additions and 3 deletions
|
@ -519,12 +519,13 @@ XHTMLTagAction *XHTMLReader::addAction(const std::string &ns, const std::string
|
|||
}
|
||||
|
||||
XHTMLTagAction *XHTMLReader::getAction(const std::string &tag) {
|
||||
XHTMLTagAction *action = ourTagActions[tag];
|
||||
const std::string lTag = ZLUnicodeUtil::toLower(tag);
|
||||
XHTMLTagAction *action = ourTagActions[lTag];
|
||||
if (action != 0) {
|
||||
return action;
|
||||
}
|
||||
for (std::map<shared_ptr<FullNamePredicate>,XHTMLTagAction*>::const_iterator it = ourNsTagActions.begin(); it != ourNsTagActions.end(); ++it) {
|
||||
if (it->first->accepts(*this, tag)) {
|
||||
if (it->first->accepts(*this, lTag)) {
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
|
@ -706,7 +707,7 @@ void XHTMLReader::startElementHandler(const char *tag, const char **attributes)
|
|||
myModelReader.addHyperlinkLabel(myReferenceAlias + HASH + id);
|
||||
}
|
||||
|
||||
const std::string sTag = tag;
|
||||
const std::string sTag = ZLUnicodeUtil::toLower(tag);
|
||||
|
||||
std::vector<std::string> classesList;
|
||||
const char *aClasses = attributeValue(attributes, "class");
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
|
||||
|
@ -484,6 +485,21 @@ std::string ZLUnicodeUtil::toLower(const std::string &utf8String) {
|
|||
return utf8String;
|
||||
}
|
||||
|
||||
bool isAscii = true;
|
||||
const int size = utf8String.size();
|
||||
for (int i = size - 1; i >= 0; --i) {
|
||||
if ((utf8String[i] & 0x80) != 0) {
|
||||
isAscii = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isAscii) {
|
||||
std::string result(size, ' ');
|
||||
for (int i = size - 1; i >= 0; --i) {
|
||||
result[i] = std::tolower(utf8String[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
JNIEnv *env = AndroidUtil::getEnv();
|
||||
jstring javaString = AndroidUtil::createJavaString(env, utf8String);
|
||||
jstring lowerCased = AndroidUtil::Method_java_lang_String_toLowerCase->callForJavaString(javaString);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue