Bug 504422 - Be smarter with our strings for AUTOCOMPLETE_MATCH SQL function

Avoids an unnecessary string copy on every invocation of AUTOCOMPLETE_MATCH.
r=dietrich
This commit is contained in:
Shawn Wilsher 2009-08-10 15:15:22 -07:00
parent f44d6a5d36
commit 53cd9afdef
2 changed files with 23 additions and 21 deletions

View File

@ -71,29 +71,29 @@ namespace places {
}
/* static */
nsString
MatchAutoCompleteFunction::fixupURISpec(const nsDependentCString &aURISpec)
void
MatchAutoCompleteFunction::fixupURISpec(const nsCString &aURISpec,
nsString &_fixedSpec)
{
nsCAutoString unescapedSpec;
nsCString unescapedSpec;
(void)NS_UnescapeURL(aURISpec, esc_SkipControl | esc_AlwaysCopy,
unescapedSpec);
// If this unescaped string is valid UTF-8, we'll convert it. Otherwise,
// we will simply convert our original string.
nsString fixedSpec;
NS_ASSERTION(_fixedSpec.IsEmpty(),
"Passing a non-empty string as an out parameter!");
if (IsUTF8(unescapedSpec))
CopyUTF8toUTF16(unescapedSpec, fixedSpec);
CopyUTF8toUTF16(unescapedSpec, _fixedSpec);
else
CopyUTF8toUTF16(aURISpec, fixedSpec);
CopyUTF8toUTF16(aURISpec, _fixedSpec);
if (StringBeginsWith(fixedSpec, NS_LITERAL_STRING("http://")))
fixedSpec.Cut(0, 7);
else if (StringBeginsWith(fixedSpec, NS_LITERAL_STRING("https://")))
fixedSpec.Cut(0, 8);
else if (StringBeginsWith(fixedSpec, NS_LITERAL_STRING("ftp://")))
fixedSpec.Cut(0, 6);
return fixedSpec;
if (StringBeginsWith(_fixedSpec, NS_LITERAL_STRING("http://")))
_fixedSpec.Cut(0, 7);
else if (StringBeginsWith(_fixedSpec, NS_LITERAL_STRING("https://")))
_fixedSpec.Cut(0, 8);
else if (StringBeginsWith(_fixedSpec, NS_LITERAL_STRING("ftp://")))
_fixedSpec.Cut(0, 6);
}
/* static */
@ -214,9 +214,9 @@ namespace places {
#define HAS_BEHAVIOR(aBitName) \
(searchBehavior & mozIPlacesAutoComplete::BEHAVIOR_##aBitName)
nsDependentString searchString;
nsAutoString searchString;
(void)aArguments->GetString(kArgSearchString, searchString);
nsDependentCString url;
nsCString url;
(void)aArguments->GetUTF8String(kArgIndexURL, url);
// We only want to filter javascript: URLs if we are not supposed to search
@ -232,7 +232,7 @@ namespace places {
PRInt32 visitCount = aArguments->AsInt32(kArgIndexVisitCount);
bool typed = aArguments->AsInt32(kArgIndexTyped) ? true : false;
bool bookmark = aArguments->AsInt32(kArgIndexBookmark) ? true : false;
nsDependentString tags;
nsAutoString tags;
(void)aArguments->GetString(kArgIndexTags, tags);
// Make sure we match all the filter requirements. If a given restriction
@ -250,13 +250,14 @@ namespace places {
}
// Clean up our URI spec and prepare it for searching.
nsString fixedURI = fixupURISpec(url);
nsString fixedURI;
fixupURISpec(url, fixedURI);
// Obtain our search function.
PRInt32 matchBehavior = aArguments->AsInt32(kArgIndexMatchBehavior);
searchFunctionPtr searchFunction = getSearchFunction(matchBehavior);
nsDependentString title;
nsAutoString title;
(void)aArguments->GetString(kArgIndexTitle, title);
// Determine if every token matches either the bookmark title, tags, page

View File

@ -197,9 +197,10 @@ private:
*
* @param aURISpec
* The spec of the URI to prepare for searching.
* @return the new string to use for the URI spec.
* @param _fixedSpec
* An out parameter that is the fixed up string.
*/
static nsString fixupURISpec(const nsDependentCString &aURISpec);
static void fixupURISpec(const nsCString &aURISpec, nsString &_fixedSpec);
};
} // namespace places