Bug 289010 - Move nsVoidArray/nsCOMArray to the XPCOM glue, and a few other things to make the glue easier to use, r=shaver+darin . The following files were CVS-copied from xpcom/ds to xpcom/glue:
nsVoidArray.h nsVoidArray.cpp nsCOMArray.h nsCOMArray.cpp nsQuickSort.h nsQuickSort.cpp git-svn-id: svn://10.0.0.236/trunk@184052 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -44,6 +44,8 @@ VPATH = @srcdir@
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
include $(srcdir)/../glue/objs.mk
|
||||
|
||||
EXTRA_DEPS += $(srcdir)/../glue/objs.mk
|
||||
|
||||
MODULE = xpcom
|
||||
LIBRARY_NAME = xpcom_core
|
||||
|
||||
|
||||
@@ -69,7 +69,6 @@ CPPSRCS = \
|
||||
nsObserverService.cpp \
|
||||
nsProperties.cpp \
|
||||
nsPersistentProperties.cpp \
|
||||
nsQuickSort.cpp \
|
||||
nsRecyclingAllocator.cpp \
|
||||
nsStaticNameTable.cpp \
|
||||
nsStringEnumerator.cpp \
|
||||
@@ -78,11 +77,9 @@ CPPSRCS = \
|
||||
nsSupportsPrimitives.cpp \
|
||||
nsUnicharBuffer.cpp \
|
||||
nsVariant.cpp \
|
||||
nsVoidArray.cpp \
|
||||
nsTextFormatter.cpp \
|
||||
nsTimelineService.cpp \
|
||||
nsValueArray.cpp \
|
||||
nsCOMArray.cpp \
|
||||
nsArray.cpp \
|
||||
nsArrayEnumerator.cpp \
|
||||
nsHashPropertyBag.cpp \
|
||||
@@ -103,7 +100,6 @@ EXPORTS = \
|
||||
nsIUnicharBuffer.h \
|
||||
nsInt64.h \
|
||||
nsObserverService.h \
|
||||
nsQuickSort.h \
|
||||
nsRecyclingAllocator.h \
|
||||
nsStaticNameTable.h \
|
||||
nsStaticAtom.h \
|
||||
@@ -112,12 +108,10 @@ EXPORTS = \
|
||||
nsTime.h \
|
||||
nsUnitConversion.h \
|
||||
nsVariant.h \
|
||||
nsVoidArray.h \
|
||||
nsTextFormatter.h \
|
||||
nsValueArray.h \
|
||||
nsArray.h \
|
||||
nsArrayEnumerator.h \
|
||||
nsCOMArray.h \
|
||||
nsStringEnumerator.h \
|
||||
nsAutoBuffer.h \
|
||||
nsHashPropertyBag.h \
|
||||
|
||||
@@ -43,6 +43,8 @@ VPATH = @srcdir@
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
include $(srcdir)/objs.mk
|
||||
|
||||
EXTRA_DEPS += $(srcdir)/objs.mk
|
||||
|
||||
DIRS = standalone
|
||||
|
||||
MODULE = xpcom
|
||||
@@ -68,13 +70,18 @@ CPPSRCS = \
|
||||
EXPORTS = \
|
||||
pldhash.h \
|
||||
nsBaseHashtable.h \
|
||||
nsCOMArray.h \
|
||||
nsCRTGlue.h \
|
||||
nsClassHashtable.h \
|
||||
nsDataHashtable.h \
|
||||
nsHashKeys.h \
|
||||
nsINIParser.h \
|
||||
nsInterfaceHashtable.h \
|
||||
nsQuickSort.h \
|
||||
nsStringGlue.h \
|
||||
nsRefPtrHashtable.h \
|
||||
nsTHashtable.h \
|
||||
nsVoidArray.h \
|
||||
$(NULL)
|
||||
|
||||
SDK_HEADERS = \
|
||||
|
||||
87
mozilla/xpcom/glue/nsCRTGlue.cpp
Normal file
87
mozilla/xpcom/glue/nsCRTGlue.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Application Update.
|
||||
* This file is based on code originally located at
|
||||
* mozilla/toolkit/mozapps/update/src/updater/updater.cpp
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Benjamin Smedberg <benjamin@smedbergs.us>
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Darin Fisher <darin@meer.net>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsCRTGlue.h"
|
||||
|
||||
const char*
|
||||
NS_strspnp(const char *delims, const char *str)
|
||||
{
|
||||
const char *d;
|
||||
do {
|
||||
for (d = delims; *d != '\0'; ++d) {
|
||||
if (*str == *d) {
|
||||
++str;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (*d);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
char*
|
||||
NS_strtok(const char *delims, char **str)
|
||||
{
|
||||
if (!*str)
|
||||
return NULL;
|
||||
|
||||
char *ret = (char*) NS_strspnp(delims, *str);
|
||||
|
||||
if (!*ret) {
|
||||
*str = ret;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *i = ret;
|
||||
do {
|
||||
for (const char *d = delims; *d != '\0'; ++d) {
|
||||
if (*i == *d) {
|
||||
*i = '\0';
|
||||
*str = ++i;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
++i;
|
||||
} while (*i);
|
||||
|
||||
*str = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
74
mozilla/xpcom/glue/nsCRTGlue.h
Normal file
74
mozilla/xpcom/glue/nsCRTGlue.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla XPCOM Glue.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* the Mozilla Foundation <http://www.mozilla.org/>.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Benjamin Smedberg <benjamin@smedbergs.us>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsCRTGlue_h__
|
||||
#define nsCRTGlue_h__
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
/**
|
||||
* Scan a string for the first character that is *not* in a set of
|
||||
* delimiters. If the string is only delimiter characters, the end of the
|
||||
* string is returned.
|
||||
*
|
||||
* @param delims The set of delimiters (null-terminated)
|
||||
* @param str The string to search (null-terminated)
|
||||
*/
|
||||
const char* NS_COM_GLUE
|
||||
NS_strspnp(const char *delims, const char *str);
|
||||
|
||||
/**
|
||||
* Tokenize a string. This function is similar to the strtok function in the
|
||||
* C standard library, but it does use static variables to maintain state
|
||||
* and is therefore thread and reentrancy-safe.
|
||||
*
|
||||
* Any leading delimiters in str are skipped. Then the string is scanned
|
||||
* until an additional delimiter or end-of-string is found. The final
|
||||
* delimiter is set to '\0'.
|
||||
*
|
||||
* @param delims The set of delimiters.
|
||||
* @param str The string to search. This is an in-out parameter; it is
|
||||
* reset to the end of the found token + 1, or to the
|
||||
* end-of-string if there are no more tokens.
|
||||
* @return The token. If no token is found (the string is only
|
||||
* delimiter characters), NULL is returned.
|
||||
*/
|
||||
char* NS_COM_GLUE
|
||||
NS_strtok(const char *delims, char **str);
|
||||
|
||||
#endif // nsCRTGlue_h__
|
||||
@@ -44,12 +44,7 @@
|
||||
#include "pldhash.h"
|
||||
#include NEW_H
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
#include "nsAString.h"
|
||||
#include "nsString.h"
|
||||
#else
|
||||
#include "nsStringAPI.h"
|
||||
#endif
|
||||
#include "nsStringGlue.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "nsINIParser.h"
|
||||
#include "nsError.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsCRTGlue.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@@ -89,59 +90,6 @@ nsINIParser::Init(const char *aPath)
|
||||
return InitFromFILE(fd);
|
||||
}
|
||||
|
||||
// Based on toolkit/mozapps/updater/src/updater/updater.cpp
|
||||
// we could use nsCRT::strtok except that nsCRT isn't part of the glue,
|
||||
// and may never be due to NSPR dependencies. This should probably be declared
|
||||
// and exported in a string-management glue header.
|
||||
|
||||
/**
|
||||
* Scan "str" for the first character that is not in "delims".
|
||||
*/
|
||||
static char*
|
||||
mstrspnp(const char *delims, char *str)
|
||||
{
|
||||
const char *d;
|
||||
do {
|
||||
for (d = delims; *d != '\0'; ++d) {
|
||||
if (*str == *d) {
|
||||
++str;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (*d);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
static char*
|
||||
mstrtok(const char *delims, char **str)
|
||||
{
|
||||
if (!*str)
|
||||
return NULL;
|
||||
|
||||
char *ret = mstrspnp(delims, *str);
|
||||
|
||||
if (!*ret) {
|
||||
*str = ret;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *i = ret;
|
||||
do {
|
||||
for (const char *d = delims; *d != '\0'; ++d) {
|
||||
if (*i == *d) {
|
||||
*i = '\0';
|
||||
*str = ++i;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
++i;
|
||||
} while (*i);
|
||||
|
||||
*str = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const char kNL[] = "\r\n";
|
||||
static const char kEquals[] = "=";
|
||||
static const char kWhitespace[] = " \t";
|
||||
@@ -181,11 +129,11 @@ nsINIParser::InitFromFILE(FILE *fd)
|
||||
INIValue *last = nsnull;
|
||||
|
||||
// outer loop tokenizes into lines
|
||||
while (char *token = mstrtok(kNL, &buffer)) {
|
||||
while (char *token = NS_strtok(kNL, &buffer)) {
|
||||
if (token[0] == '#' || token[0] == ';') // it's a comment
|
||||
continue;
|
||||
|
||||
token = mstrspnp(kWhitespace, token);
|
||||
token = (char*) NS_strspnp(kWhitespace, token);
|
||||
if (!*token) // empty line
|
||||
continue;
|
||||
|
||||
@@ -194,8 +142,8 @@ nsINIParser::InitFromFILE(FILE *fd)
|
||||
currSection = token;
|
||||
last = nsnull;
|
||||
|
||||
char *rb = mstrtok(kRBracket, &token);
|
||||
if (!rb || mstrtok(kWhitespace, &token)) {
|
||||
char *rb = NS_strtok(kRBracket, &token);
|
||||
if (!rb || NS_strtok(kWhitespace, &token)) {
|
||||
// there's either an unclosed [Section or a [Section]Moretext!
|
||||
// we could frankly decide that this INI file is malformed right
|
||||
// here and stop, but we won't... keep going, looking for
|
||||
@@ -213,7 +161,7 @@ nsINIParser::InitFromFILE(FILE *fd)
|
||||
}
|
||||
|
||||
char *key = token;
|
||||
char *e = mstrtok(kEquals, &token);
|
||||
char *e = NS_strtok(kEquals, &token);
|
||||
if (!e)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -37,8 +37,6 @@
|
||||
#include "prtypes.h"
|
||||
#include "nsQuickSort.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
#if !defined(DEBUG) && (defined(__cplusplus) || defined(__gcc))
|
||||
# ifndef INLINE
|
||||
# define INLINE inline
|
||||
@@ -95,7 +93,7 @@ med3(char *a, char *b, char *c, cmp_t* cmp, void *data)
|
||||
:(cmp(b, c, data) > 0 ? b : (cmp(a, c, data) < 0 ? a : c ));
|
||||
}
|
||||
|
||||
void NS_QuickSort (
|
||||
extern "C" void NS_QuickSort (
|
||||
void *a,
|
||||
unsigned int n,
|
||||
unsigned int es,
|
||||
@@ -178,5 +176,3 @@ loop: SWAPINIT(a, es);
|
||||
}
|
||||
/* NS_QuickSort(pn - r, r / es, es, cmp, data);*/
|
||||
}
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
@@ -44,6 +44,8 @@
|
||||
#define nsQuickSort_h___
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
/**
|
||||
@@ -58,9 +60,9 @@ PR_BEGIN_EXTERN_C
|
||||
* + greater than zero if the second element should be before the first
|
||||
* 5. extra data to pass to comparison function
|
||||
*/
|
||||
PR_EXTERN(void) NS_QuickSort(void *, unsigned int, unsigned int,
|
||||
int (*)(const void *, const void *, void *),
|
||||
void *);
|
||||
void NS_COM_GLUE NS_QuickSort(void *, unsigned int, unsigned int,
|
||||
int (*)(const void *, const void *, void *),
|
||||
void *);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
|
||||
54
mozilla/xpcom/glue/nsStringGlue.h
Normal file
54
mozilla/xpcom/glue/nsStringGlue.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla XPCOM Glue.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* the Mozilla Foundation <http://www.mozilla.org/>.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Benjamin Smedberg <benjamin@smedbergs.us>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* @file nsStringGlue.h
|
||||
* This header exists solely to #include the proper internal/frozen string
|
||||
* headers, depending on whether MOZILLA_INTERNAL_API is defined.
|
||||
*/
|
||||
|
||||
#ifndef nsStringGlue_h__
|
||||
#define nsStringGlue_h__
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
#include "nsString.h"
|
||||
#else
|
||||
#include "nsStringAPI.h"
|
||||
#endif
|
||||
|
||||
#endif // nsStringGlue_h__
|
||||
@@ -34,12 +34,14 @@
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsQuickSort.h"
|
||||
#include "prmem.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsString.h"
|
||||
#include "prbit.h"
|
||||
#include "nsISupportsImpl.h" // for nsTraceRefcnt
|
||||
#include "nsCRTGlue.h"
|
||||
|
||||
/**
|
||||
* Grow the array by at least this many elements at a time.
|
||||
@@ -168,7 +170,7 @@ PRBool nsVoidArray::SizeTo(PRInt32 aSize)
|
||||
{
|
||||
if (isOwner)
|
||||
{
|
||||
PR_Free(NS_REINTERPRET_CAST(char *, mImpl));
|
||||
free(NS_REINTERPRET_CAST(char *, mImpl));
|
||||
if (hasAuto) {
|
||||
NS_STATIC_CAST(nsAutoVoidArray*, this)->ResetToAutoBuffer();
|
||||
}
|
||||
@@ -193,7 +195,7 @@ PRBool nsVoidArray::SizeTo(PRInt32 aSize)
|
||||
return PR_TRUE; // can't make it that small, ignore request
|
||||
}
|
||||
|
||||
char* bytes = (char *) PR_Realloc(mImpl,SIZEOF_IMPL(aSize));
|
||||
char* bytes = (char *) realloc(mImpl,SIZEOF_IMPL(aSize));
|
||||
Impl* newImpl = NS_REINTERPRET_CAST(Impl*, bytes);
|
||||
if (!newImpl)
|
||||
return PR_FALSE;
|
||||
@@ -226,7 +228,7 @@ PRBool nsVoidArray::SizeTo(PRInt32 aSize)
|
||||
|
||||
// just allocate an array
|
||||
// allocate the exact size requested
|
||||
char* bytes = (char *) PR_Malloc(SIZEOF_IMPL(aSize));
|
||||
char* bytes = (char *) malloc(SIZEOF_IMPL(aSize));
|
||||
Impl* newImpl = NS_REINTERPRET_CAST(Impl*, bytes);
|
||||
if (!newImpl)
|
||||
return PR_FALSE;
|
||||
@@ -371,7 +373,7 @@ nsVoidArray::~nsVoidArray()
|
||||
{
|
||||
MOZ_COUNT_DTOR(nsVoidArray);
|
||||
if (mImpl && IsArrayOwner())
|
||||
PR_Free(NS_REINTERPRET_CAST(char*, mImpl));
|
||||
free(NS_REINTERPRET_CAST(char*, mImpl));
|
||||
}
|
||||
|
||||
PRInt32 nsVoidArray::IndexOf(void* aPossibleElement) const
|
||||
@@ -629,7 +631,7 @@ void nsVoidArray::Compact()
|
||||
NS_STATIC_CAST(nsAutoVoidArray*, this)->ResetToAutoBuffer();
|
||||
memcpy(mImpl->mArray, oldImpl->mArray,
|
||||
count * sizeof(mImpl->mArray[0]));
|
||||
PR_Free(NS_REINTERPRET_CAST(char *, oldImpl));
|
||||
free(NS_REINTERPRET_CAST(char *, oldImpl));
|
||||
}
|
||||
else if (GetArraySize() > count)
|
||||
{
|
||||
@@ -846,7 +848,25 @@ nsStringArray::Clear(void)
|
||||
PR_STATIC_CALLBACK(int)
|
||||
CompareString(const nsString* aString1, const nsString* aString2, void*)
|
||||
{
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
return Compare(*aString1, *aString2);
|
||||
#else
|
||||
const PRUnichar* s1;
|
||||
const PRUnichar* s2;
|
||||
PRUint32 len1 = NS_StringGetData(*aString1, &s1);
|
||||
PRUint32 len2 = NS_StringGetData(*aString2, &s2);
|
||||
int r = memcmp(s1, s2, sizeof(PRUnichar) * PR_MIN(len1, len2));
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
if (len1 < len2)
|
||||
return -1;
|
||||
|
||||
if (len1 > len2)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void nsStringArray::Sort(void)
|
||||
@@ -907,18 +927,18 @@ void
|
||||
nsCStringArray::ParseString(const char* string, const char* delimiter)
|
||||
{
|
||||
if (string && *string && delimiter && *delimiter) {
|
||||
char *newStr;
|
||||
char *rest = nsCRT::strdup(string);
|
||||
char *token = nsCRT::strtok(rest, delimiter, &newStr);
|
||||
char *rest = strdup(string);
|
||||
char *newStr = rest;
|
||||
char *token = NS_strtok(delimiter, &newStr);
|
||||
|
||||
while (token) {
|
||||
if (*token) {
|
||||
/* calling AppendElement(void*) to avoid extra nsCString copy */
|
||||
AppendElement(new nsCString(token));
|
||||
}
|
||||
token = nsCRT::strtok(newStr, delimiter, &newStr);
|
||||
token = NS_strtok(delimiter, &newStr);
|
||||
}
|
||||
PR_FREEIF(rest);
|
||||
free(rest);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -988,6 +1008,7 @@ nsCStringArray::IndexOf(const nsACString& aPossibleString) const
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
PRInt32
|
||||
nsCStringArray::IndexOfIgnoreCase(const nsACString& aPossibleString) const
|
||||
{
|
||||
@@ -1007,6 +1028,7 @@ nsCStringArray::IndexOfIgnoreCase(const nsACString& aPossibleString) const
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
PRBool
|
||||
nsCStringArray::InsertCStringAt(const nsACString& aCString, PRInt32 aIndex)
|
||||
@@ -1043,6 +1065,7 @@ nsCStringArray::RemoveCString(const nsACString& aCString)
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
PRBool
|
||||
nsCStringArray::RemoveCStringIgnoreCase(const nsACString& aCString)
|
||||
{
|
||||
@@ -1053,6 +1076,7 @@ nsCStringArray::RemoveCStringIgnoreCase(const nsACString& aCString)
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
PRBool nsCStringArray::RemoveCStringAt(PRInt32 aIndex)
|
||||
{
|
||||
@@ -1081,24 +1105,46 @@ nsCStringArray::Clear(void)
|
||||
PR_STATIC_CALLBACK(int)
|
||||
CompareCString(const nsCString* aCString1, const nsCString* aCString2, void*)
|
||||
{
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
return Compare(*aCString1, *aCString2);
|
||||
#else
|
||||
const char* s1;
|
||||
const char* s2;
|
||||
PRUint32 len1 = NS_CStringGetData(*aCString1, &s1);
|
||||
PRUint32 len2 = NS_CStringGetData(*aCString2, &s2);
|
||||
int r = memcmp(s1, s2, PR_MIN(len1, len2));
|
||||
if (r)
|
||||
return r;
|
||||
|
||||
if (len1 < len2)
|
||||
return -1;
|
||||
|
||||
if (len1 > len2)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
PR_STATIC_CALLBACK(int)
|
||||
CompareCStringIgnoreCase(const nsCString* aCString1, const nsCString* aCString2, void*)
|
||||
{
|
||||
return Compare(*aCString1, *aCString2, nsCaseInsensitiveCStringComparator());
|
||||
}
|
||||
#endif
|
||||
|
||||
void nsCStringArray::Sort(void)
|
||||
{
|
||||
Sort(CompareCString, nsnull);
|
||||
}
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
void nsCStringArray::SortIgnoreCase(void)
|
||||
{
|
||||
Sort(CompareCStringIgnoreCase, nsnull);
|
||||
}
|
||||
#endif
|
||||
|
||||
void nsCStringArray::Sort(nsCStringArrayComparatorFunc aFunc, void* aData)
|
||||
{
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
//#define DEBUG_VOIDARRAY 1
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsAString.h"
|
||||
#include "nsStringGlue.h"
|
||||
|
||||
// Comparator callback function for sorting array values.
|
||||
typedef int (* PR_CALLBACK nsVoidArrayComparatorFunc)
|
||||
@@ -50,7 +50,7 @@ typedef int (* PR_CALLBACK nsVoidArrayComparatorFunc)
|
||||
typedef PRBool (* PR_CALLBACK nsVoidArrayEnumFunc)(void* aElement, void *aData);
|
||||
|
||||
/// A basic zero-based array of void*'s that manages its own memory
|
||||
class NS_COM nsVoidArray {
|
||||
class NS_COM_GLUE nsVoidArray {
|
||||
public:
|
||||
nsVoidArray();
|
||||
nsVoidArray(PRInt32 aCount); // initial count of aCount elements set to nsnull
|
||||
@@ -183,7 +183,7 @@ private:
|
||||
|
||||
|
||||
// A zero-based array with a bit of automatic internal storage
|
||||
class NS_COM nsAutoVoidArray : public nsVoidArray {
|
||||
class NS_COM_GLUE nsAutoVoidArray : public nsVoidArray {
|
||||
public:
|
||||
nsAutoVoidArray();
|
||||
|
||||
@@ -206,7 +206,7 @@ typedef int (* PR_CALLBACK nsStringArrayComparatorFunc)
|
||||
|
||||
typedef PRBool (*nsStringArrayEnumFunc)(nsString& aElement, void *aData);
|
||||
|
||||
class NS_COM nsStringArray: private nsVoidArray
|
||||
class NS_COM_GLUE nsStringArray: private nsVoidArray
|
||||
{
|
||||
public:
|
||||
nsStringArray(void);
|
||||
@@ -260,7 +260,7 @@ typedef int (* PR_CALLBACK nsCStringArrayComparatorFunc)
|
||||
|
||||
typedef PRBool (*nsCStringArrayEnumFunc)(nsCString& aElement, void *aData);
|
||||
|
||||
class NS_COM nsCStringArray: private nsVoidArray
|
||||
class NS_COM_GLUE nsCStringArray: private nsVoidArray
|
||||
{
|
||||
public:
|
||||
nsCStringArray(void);
|
||||
@@ -285,7 +285,10 @@ public:
|
||||
nsCString* operator[](PRInt32 aIndex) const { return CStringAt(aIndex); }
|
||||
|
||||
PRInt32 IndexOf(const nsACString& aPossibleString) const;
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
PRInt32 IndexOfIgnoreCase(const nsACString& aPossibleString) const;
|
||||
#endif
|
||||
|
||||
PRBool InsertCStringAt(const nsACString& aCString, PRInt32 aIndex);
|
||||
|
||||
@@ -296,7 +299,11 @@ public:
|
||||
}
|
||||
|
||||
PRBool RemoveCString(const nsACString& aCString);
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
PRBool RemoveCStringIgnoreCase(const nsACString& aCString);
|
||||
#endif
|
||||
|
||||
PRBool RemoveCStringAt(PRInt32 aIndex);
|
||||
void Clear(void);
|
||||
|
||||
@@ -305,7 +312,11 @@ public:
|
||||
}
|
||||
|
||||
void Sort(void);
|
||||
|
||||
#ifdef MOZILLA_INTERNAL_API
|
||||
void SortIgnoreCase(void);
|
||||
#endif
|
||||
|
||||
void Sort(nsCStringArrayComparatorFunc aFunc, void* aData);
|
||||
|
||||
PRBool EnumerateForwards(nsCStringArrayEnumFunc aFunc, void* aData);
|
||||
@@ -341,7 +352,7 @@ private:
|
||||
// today, there should not be any virtualness to it to avoid the vtable
|
||||
// ptr overhead.
|
||||
|
||||
class NS_COM nsSmallVoidArray : private nsVoidArray
|
||||
class NS_COM_GLUE nsSmallVoidArray : private nsVoidArray
|
||||
{
|
||||
public:
|
||||
~nsSmallVoidArray();
|
||||
|
||||
@@ -42,6 +42,8 @@ XPCOM_GLUE_SRC_CSRCS = $(addprefix $(topsrcdir)/xpcom/glue/, $(XPCOM_GLUE_SRC_LC
|
||||
|
||||
XPCOM_GLUE_SRC_LCPPSRCS = \
|
||||
nsCOMPtr.cpp \
|
||||
nsCOMArray.cpp \
|
||||
nsCRTGlue.cpp \
|
||||
nsComponentManagerUtils.cpp \
|
||||
nsDebug.cpp \
|
||||
nsID.cpp \
|
||||
@@ -53,6 +55,8 @@ XPCOM_GLUE_SRC_LCPPSRCS = \
|
||||
nsGREGlue.cpp \
|
||||
nsVersionComparator.cpp \
|
||||
nsTHashtable.cpp \
|
||||
nsQuickSort.cpp \
|
||||
nsVoidArray.cpp \
|
||||
$(NULL)
|
||||
|
||||
XPCOM_GLUE_SRC_CPPSRCS = $(addprefix $(topsrcdir)/xpcom/glue/, $(XPCOM_GLUE_SRC_LCPPSRCS))
|
||||
|
||||
@@ -43,6 +43,8 @@ VPATH = @srcdir@
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
include $(srcdir)/../objs.mk
|
||||
|
||||
EXTRA_DEPS += $(srcdir)/../objs.mk
|
||||
|
||||
MODULE = xpcom
|
||||
LIBRARY_NAME = xpcomglue
|
||||
|
||||
|
||||
@@ -923,6 +923,8 @@ public:
|
||||
|
||||
NS_HIDDEN_(void) Cut( index_type cutStart, size_type cutLength ) { Replace(cutStart, cutLength, nsnull, 0); }
|
||||
|
||||
NS_HIDDEN_(void) Truncate() { SetLength(0); }
|
||||
|
||||
NS_HIDDEN_(PRBool) Equals( const self_type &other ) const {
|
||||
const char_type *cself;
|
||||
const char_type *cother;
|
||||
@@ -1040,6 +1042,8 @@ public:
|
||||
|
||||
NS_HIDDEN_(void) Cut( index_type cutStart, size_type cutLength ) { Replace(cutStart, cutLength, nsnull, 0); }
|
||||
|
||||
NS_HIDDEN_(void) Truncate() { SetLength(0); }
|
||||
|
||||
NS_HIDDEN_(PRBool) Equals( const self_type &other ) const {
|
||||
const char_type *cself;
|
||||
const char_type *cother;
|
||||
|
||||
Reference in New Issue
Block a user