Skip to content
Snippets Groups Projects
Commit 2e5b874f authored by Alberto Massari's avatar Alberto Massari
Browse files

Use XMLString::compareIStringASCII to avoid the penalty of calling XMLString::lowerCase

git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@355106 13f79535-47bb-0310-9956-ffa450edef68
parent ec2f7143
No related branches found
No related tags found
No related merge requests found
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include <xercesc/util/XMLString.hpp> #include <xercesc/util/XMLString.hpp>
#include <xercesc/util/XMLUniDefs.hpp> #include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/dom/DOMException.hpp> #include <xercesc/dom/DOMException.hpp>
#include <xercesc/util/Janitor.hpp>
XERCES_CPP_NAMESPACE_BEGIN XERCES_CPP_NAMESPACE_BEGIN
...@@ -55,21 +54,15 @@ DOMConfigurationImpl::~DOMConfigurationImpl() { ...@@ -55,21 +54,15 @@ DOMConfigurationImpl::~DOMConfigurationImpl() {
} }
void DOMConfigurationImpl::setParameter(const XMLCh* name, const void* value) { void DOMConfigurationImpl::setParameter(const XMLCh* name, const void* value) {
if(!canSetParameter(name, value)) {
XMLCh* lowerCaseName = XMLString::replicate(name, fMemoryManager);
ArrayJanitor<XMLCh> janName(lowerCaseName, fMemoryManager);
XMLString::lowerCaseASCII(lowerCaseName);
if(!canSetParameter(lowerCaseName, value)) {
throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, fMemoryManager); throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, fMemoryManager);
} }
if(XMLString::equals(lowerCaseName, XMLUni::fgDOMErrorHandler)) { if(XMLString::compareIStringASCII(name, XMLUni::fgDOMErrorHandler)==0) {
fErrorHandler = (DOMErrorHandler*)value; fErrorHandler = (DOMErrorHandler*)value;
} else if (XMLString::equals(lowerCaseName, XMLUni::fgDOMSchemaType)) { } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaType)==0) {
fSchemaType = (XMLCh*)value; fSchemaType = (XMLCh*)value;
} else if (XMLString::equals(lowerCaseName, XMLUni::fgDOMSchemaLocation)) { } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaLocation)==0) {
fSchemaLocation = (XMLCh*)value; fSchemaLocation = (XMLCh*)value;
} else { // canSetParameter above should take care of this case } else { // canSetParameter above should take care of this case
throw DOMException(DOMException::NOT_FOUND_ERR, 0, fMemoryManager); throw DOMException(DOMException::NOT_FOUND_ERR, 0, fMemoryManager);
...@@ -78,16 +71,11 @@ void DOMConfigurationImpl::setParameter(const XMLCh* name, const void* value) { ...@@ -78,16 +71,11 @@ void DOMConfigurationImpl::setParameter(const XMLCh* name, const void* value) {
} }
void DOMConfigurationImpl::setParameter(const XMLCh* name, bool value) { void DOMConfigurationImpl::setParameter(const XMLCh* name, bool value) {
XMLCh* lowerCaseName = XMLString::replicate(name, fMemoryManager); if(!canSetParameter(name, value)) {
ArrayJanitor<XMLCh> janName(lowerCaseName, fMemoryManager);
XMLString::lowerCaseASCII(lowerCaseName);
if(!canSetParameter(lowerCaseName, value)) {
throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, fMemoryManager); throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, fMemoryManager);
} }
DOMConfigurationFeature whichFlag = getFeatureFlag(lowerCaseName); DOMConfigurationFeature whichFlag = getFeatureFlag(name);
if(value) { if(value) {
featureValues |= whichFlag; featureValues |= whichFlag;
} else { } else {
...@@ -101,15 +89,9 @@ void DOMConfigurationImpl::setParameter(const XMLCh* name, bool value) { ...@@ -101,15 +89,9 @@ void DOMConfigurationImpl::setParameter(const XMLCh* name, bool value) {
// -------------------------------------- // --------------------------------------
const void* DOMConfigurationImpl::getParameter(const XMLCh* name) const { const void* DOMConfigurationImpl::getParameter(const XMLCh* name) const {
XMLCh* lowerCaseName = XMLString::replicate(name, fMemoryManager);
ArrayJanitor<XMLCh> janName(lowerCaseName, fMemoryManager);
XMLString::lowerCaseASCII(lowerCaseName);
DOMConfigurationFeature whichFlag; DOMConfigurationFeature whichFlag;
try { try {
whichFlag = getFeatureFlag(lowerCaseName); whichFlag = getFeatureFlag(name);
if(featureValues & whichFlag) { if(featureValues & whichFlag) {
return (void*)true; return (void*)true;
} else { } else {
...@@ -117,11 +99,11 @@ const void* DOMConfigurationImpl::getParameter(const XMLCh* name) const { ...@@ -117,11 +99,11 @@ const void* DOMConfigurationImpl::getParameter(const XMLCh* name) const {
} }
} catch (DOMException&) { } catch (DOMException&) {
// must not be a boolean parameter // must not be a boolean parameter
if(XMLString::equals(lowerCaseName, XMLUni::fgDOMErrorHandler)) { if(XMLString::compareIStringASCII(name, XMLUni::fgDOMErrorHandler)==0) {
return fErrorHandler; return fErrorHandler;
} else if (XMLString::equals(lowerCaseName, XMLUni::fgDOMSchemaType)) { } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaType)==0) {
return fSchemaType; return fSchemaType;
} else if (XMLString::equals(lowerCaseName, XMLUni::fgDOMSchemaLocation)) { } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaLocation)==0) {
return fSchemaLocation; return fSchemaLocation;
} else { } else {
throw DOMException(DOMException::NOT_FOUND_ERR, 0, fMemoryManager); throw DOMException(DOMException::NOT_FOUND_ERR, 0, fMemoryManager);
...@@ -144,16 +126,11 @@ bool DOMConfigurationImpl::canSetParameter(const XMLCh* name, const void* /*valu ...@@ -144,16 +126,11 @@ bool DOMConfigurationImpl::canSetParameter(const XMLCh* name, const void* /*valu
* 2) if an [optional] feature has no supporting code, then return false * 2) if an [optional] feature has no supporting code, then return false
**/ **/
XMLCh* lowerCaseName = XMLString::replicate(name, fMemoryManager); if(XMLString::compareIStringASCII(name, XMLUni::fgDOMErrorHandler)==0) {
ArrayJanitor<XMLCh> janName(lowerCaseName, fMemoryManager);
XMLString::lowerCaseASCII(lowerCaseName);
if(XMLString::equals(lowerCaseName, XMLUni::fgDOMErrorHandler)) {
return true; // required // return true; // required //
} else if (XMLString::equals(lowerCaseName, XMLUni::fgDOMSchemaType)) { } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaType)==0) {
return false; // optional // return false; // optional //
} else if (XMLString::equals(lowerCaseName, XMLUni::fgDOMSchemaLocation)) { } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSchemaLocation)==0) {
return false; // optional // return false; // optional //
} }
return false; return false;
...@@ -168,12 +145,7 @@ bool DOMConfigurationImpl::canSetParameter(const XMLCh* name, bool booleanValue) ...@@ -168,12 +145,7 @@ bool DOMConfigurationImpl::canSetParameter(const XMLCh* name, bool booleanValue)
* 2) if an [optional] feature has no supporting code, then return false * 2) if an [optional] feature has no supporting code, then return false
**/ **/
XMLCh* lowerCaseName = XMLString::replicate(name, fMemoryManager); DOMConfigurationFeature whichFlag = getFeatureFlag(name);
ArrayJanitor<XMLCh> janName(lowerCaseName, fMemoryManager);
XMLString::lowerCaseASCII(lowerCaseName);
DOMConfigurationFeature whichFlag = getFeatureFlag(lowerCaseName);
switch (whichFlag) { switch (whichFlag) {
case FEATURE_CANONICAL_FORM: case FEATURE_CANONICAL_FORM:
if(booleanValue) return false; // optional // if(booleanValue) return false; // optional //
...@@ -231,38 +203,33 @@ const DOMStringList* DOMConfigurationImpl::getParameterNames() const ...@@ -231,38 +203,33 @@ const DOMStringList* DOMConfigurationImpl::getParameterNames() const
// ------------------------------------------- // -------------------------------------------
DOMConfigurationImpl::DOMConfigurationFeature DOMConfigurationImpl::getFeatureFlag(const XMLCh* name) const { DOMConfigurationImpl::DOMConfigurationFeature DOMConfigurationImpl::getFeatureFlag(const XMLCh* name) const {
XMLCh* lowerCaseName = XMLString::replicate(name, fMemoryManager); if(XMLString::compareIStringASCII(name, XMLUni::fgDOMCanonicalForm)==0) {
ArrayJanitor<XMLCh> janName(lowerCaseName, fMemoryManager);
XMLString::lowerCaseASCII(lowerCaseName);
if(XMLString::equals(lowerCaseName, XMLUni::fgDOMCanonicalForm)) {
return FEATURE_CANONICAL_FORM; return FEATURE_CANONICAL_FORM;
} else if (XMLString::equals(lowerCaseName, XMLUni::fgDOMCDATASections )) { } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMCDATASections )==0) {
return FEATURE_CDATA_SECTIONS; return FEATURE_CDATA_SECTIONS;
} else if (XMLString::equals(lowerCaseName, XMLUni::fgDOMComments)) { } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMComments)==0) {
return FEATURE_COMMENTS; return FEATURE_COMMENTS;
} else if (XMLString::equals(lowerCaseName, XMLUni::fgDOMDatatypeNormalization)) { } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMDatatypeNormalization)==0) {
return FEATURE_DATATYPE_NORMALIZATION; return FEATURE_DATATYPE_NORMALIZATION;
} else if (XMLString::equals(lowerCaseName, XMLUni::fgDOMWRTDiscardDefaultContent)) { } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMWRTDiscardDefaultContent)==0) {
return FEATURE_DISCARD_DEFAULT_CONTENT; return FEATURE_DISCARD_DEFAULT_CONTENT;
} else if (XMLString::equals(lowerCaseName, XMLUni::fgDOMEntities)) { } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMEntities)==0) {
return FEATURE_ENTITIES; return FEATURE_ENTITIES;
} else if (XMLString::equals(lowerCaseName, XMLUni::fgDOMInfoset)) { } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMInfoset)==0) {
return FEATURE_INFOSET; return FEATURE_INFOSET;
} else if (XMLString::equals(lowerCaseName, XMLUni::fgDOMNamespaces)) { } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMNamespaces)==0) {
return FEATURE_NAMESPACES; return FEATURE_NAMESPACES;
} else if (XMLString::equals(lowerCaseName, XMLUni::fgDOMNamespaceDeclarations)) { } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMNamespaceDeclarations)==0) {
return FEATURE_NAMESPACE_DECLARATIONS; return FEATURE_NAMESPACE_DECLARATIONS;
} else if (XMLString::equals(lowerCaseName, XMLUni::fgDOMNormalizeCharacters)) { } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMNormalizeCharacters)==0) {
return FEATURE_NORMALIZE_CHARACTERS; return FEATURE_NORMALIZE_CHARACTERS;
} else if (XMLString::equals(lowerCaseName, XMLUni::fgDOMSplitCDATASections)) { } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMSplitCDATASections)==0) {
return FEATURE_SPLIT_CDATA_SECTIONS; return FEATURE_SPLIT_CDATA_SECTIONS;
} else if (XMLString::equals(lowerCaseName, XMLUni::fgDOMValidate)) { } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMValidate)==0) {
return FEATURE_VALIDATE; return FEATURE_VALIDATE;
} else if (XMLString::equals(lowerCaseName, XMLUni::fgDOMValidateIfSchema)) { } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMValidateIfSchema)==0) {
return FEATURE_VALIDATE_IF_SCHEMA; return FEATURE_VALIDATE_IF_SCHEMA;
} else if (XMLString::equals(lowerCaseName, XMLUni::fgDOMElementContentWhitespace)) { } else if (XMLString::compareIStringASCII(name, XMLUni::fgDOMElementContentWhitespace)==0) {
return FEATURE_ELEMENT_CONTENT_WHITESPACE; return FEATURE_ELEMENT_CONTENT_WHITESPACE;
} else { } else {
throw DOMException(DOMException::NOT_FOUND_ERR, 0, fMemoryManager); throw DOMException(DOMException::NOT_FOUND_ERR, 0, fMemoryManager);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment