Bug 226439. Some small conversion to use EqualsLiteral to see effect on code size, r+sr=dbaron. Additionally, some comments to clarify that EqualsLiteral is only for actual literals, and to properly credit Corey Kosak who showed me the template trick. Also re-enabled the template for MSVC++ 7.1, which can apparently handle it.

This commit is contained in:
roc+@cs.cmu.edu
2004-04-28 17:48:02 +00:00
parent a84d3e7ea8
commit 521d9eb8e9
8 changed files with 18 additions and 8 deletions

View File

@@ -4394,7 +4394,7 @@ NS_IMETHODIMP PresShell::GetLinkLocation(nsIDOMNode* aNode, nsAString& aLocation
if (element) { if (element) {
NS_NAMED_LITERAL_STRING(xlinkNS,"http://www.w3.org/1999/xlink"); NS_NAMED_LITERAL_STRING(xlinkNS,"http://www.w3.org/1999/xlink");
element->GetAttributeNS(xlinkNS,NS_LITERAL_STRING("type"),xlinkType); element->GetAttributeNS(xlinkNS,NS_LITERAL_STRING("type"),xlinkType);
if (xlinkType.Equals(NS_LITERAL_STRING("simple"))) { if (xlinkType.EqualsLiteral("simple")) {
element->GetAttributeNS(xlinkNS,NS_LITERAL_STRING("href"),anchorText); element->GetAttributeNS(xlinkNS,NS_LITERAL_STRING("href"),anchorText);
if (!anchorText.IsEmpty()) { if (!anchorText.IsEmpty()) {
// Resolve the full URI using baseURI property // Resolve the full URI using baseURI property

View File

@@ -2639,9 +2639,9 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetDocumentEncoding(const char* *result)
if (charset.IsEmpty()) return NS_OK; if (charset.IsEmpty()) return NS_OK;
// common charsets and those not requiring conversion first // common charsets and those not requiring conversion first
if (charset == NS_LITERAL_CSTRING("us-acsii")) { if (charset.EqualsLiteral("us-ascii")) {
*result = PL_strdup("US_ASCII"); *result = PL_strdup("US_ASCII");
} else if (charset == NS_LITERAL_CSTRING("ISO-8859-1") || } else if (charset.EqualsLiteral("ISO-8859-1") ||
!nsCRT::strncmp(PromiseFlatCString(charset).get(), "UTF", 3)) { !nsCRT::strncmp(PromiseFlatCString(charset).get(), "UTF", 3)) {
*result = ToNewCString(charset); *result = ToNewCString(charset);
} else { } else {

View File

@@ -2639,9 +2639,9 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetDocumentEncoding(const char* *result)
if (charset.IsEmpty()) return NS_OK; if (charset.IsEmpty()) return NS_OK;
// common charsets and those not requiring conversion first // common charsets and those not requiring conversion first
if (charset == NS_LITERAL_CSTRING("us-acsii")) { if (charset.EqualsLiteral("us-ascii")) {
*result = PL_strdup("US_ASCII"); *result = PL_strdup("US_ASCII");
} else if (charset == NS_LITERAL_CSTRING("ISO-8859-1") || } else if (charset.EqualsLiteral("ISO-8859-1") ||
!nsCRT::strncmp(PromiseFlatCString(charset).get(), "UTF", 3)) { !nsCRT::strncmp(PromiseFlatCString(charset).get(), "UTF", 3)) {
*result = ToNewCString(charset); *result = ToNewCString(charset);
} else { } else {

View File

@@ -4394,7 +4394,7 @@ NS_IMETHODIMP PresShell::GetLinkLocation(nsIDOMNode* aNode, nsAString& aLocation
if (element) { if (element) {
NS_NAMED_LITERAL_STRING(xlinkNS,"http://www.w3.org/1999/xlink"); NS_NAMED_LITERAL_STRING(xlinkNS,"http://www.w3.org/1999/xlink");
element->GetAttributeNS(xlinkNS,NS_LITERAL_STRING("type"),xlinkType); element->GetAttributeNS(xlinkNS,NS_LITERAL_STRING("type"),xlinkType);
if (xlinkType.Equals(NS_LITERAL_STRING("simple"))) { if (xlinkType.EqualsLiteral("simple")) {
element->GetAttributeNS(xlinkNS,NS_LITERAL_STRING("href"),anchorText); element->GetAttributeNS(xlinkNS,NS_LITERAL_STRING("href"),anchorText);
if (!anchorText.IsEmpty()) { if (!anchorText.IsEmpty()) {
// Resolve the full URI using baseURI property // Resolve the full URI using baseURI property

View File

@@ -53,7 +53,7 @@
// If some platform(s) can't handle our template that matches literal strings, // If some platform(s) can't handle our template that matches literal strings,
// then we'll disable it on those platforms. // then we'll disable it on those platforms.
#if !defined(NS_DISABLE_LITERAL_TEMPLATE) && defined(_MSC_VER) #if !defined(NS_DISABLE_LITERAL_TEMPLATE) && (defined(_MSC_VER) && _MSC_VER < 1310)
#define NS_DISABLE_LITERAL_TEMPLATE #define NS_DISABLE_LITERAL_TEMPLATE
#endif #endif

View File

@@ -47,7 +47,7 @@
// If some platform(s) can't handle our template that matches literal strings, // If some platform(s) can't handle our template that matches literal strings,
// then we'll disable it on those platforms. // then we'll disable it on those platforms.
#if !defined(NS_DISABLE_LITERAL_TEMPLATE) && defined(_MSC_VER) #if !defined(NS_DISABLE_LITERAL_TEMPLATE) && (defined(_MSC_VER) && _MSC_VER < 1310)
#define NS_DISABLE_LITERAL_TEMPLATE #define NS_DISABLE_LITERAL_TEMPLATE
#endif #endif

View File

@@ -202,6 +202,11 @@ class nsTAString_CharT
* wide strings. * wide strings.
*/ */
NS_COM PRBool EqualsASCII( const char* data, size_type len ) const; NS_COM PRBool EqualsASCII( const char* data, size_type len ) const;
// EqualsLiteral must ONLY be applied to an actual literal string.
// Do not attempt to use it with a regular char* pointer, or with a char
// array variable.
// The template trick to acquire the array length at compile time without
// using a macro is due to Corey Kosak, with much thanks.
#ifdef NS_DISABLE_LITERAL_TEMPLATE #ifdef NS_DISABLE_LITERAL_TEMPLATE
inline PRBool EqualsLiteral( const char* str ) const inline PRBool EqualsLiteral( const char* str ) const
{ {

View File

@@ -216,6 +216,11 @@ class nsTSubstring_CharT : public nsTAString_CharT
NS_COM PRBool Equals( const char_type* data, const comparator_type& comp ) const; NS_COM PRBool Equals( const char_type* data, const comparator_type& comp ) const;
NS_COM PRBool EqualsASCII( const char* data, size_type len ) const; NS_COM PRBool EqualsASCII( const char* data, size_type len ) const;
// EqualsLiteral must ONLY be applied to an actual literal string.
// Do not attempt to use it with a regular char* pointer, or with a char
// array variable.
// The template trick to acquire the array length at compile time without
// using a macro is due to Corey Kosak, with much thanks.
#ifdef NS_DISABLE_LITERAL_TEMPLATE #ifdef NS_DISABLE_LITERAL_TEMPLATE
inline PRBool EqualsLiteral( const char* str ) const inline PRBool EqualsLiteral( const char* str ) const
{ {