зеркало из https://github.com/mozilla/pjs.git
match up some reviewers comments:
- tri-license with MPL, not NPL - be consistent with policy on null in the array (it is allowed) - move Clear() into implementation file, and hide static callback there too - make sure to AddRef() on the way out of nsArray::IndexOf() - handle failure of ReplaceElementAt more gracefully bug 162115, not part of build yet
This commit is contained in:
Родитель
d8e2633092
Коммит
cd487a30e7
|
@ -1,37 +1,38 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
* 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.org code.
|
||||
* The Original Code is XPCOM Array implementation.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Alec Flett <alecf@netscape.com>
|
||||
*
|
||||
* 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
|
||||
* 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 NPL, indicate your
|
||||
* 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 NPL, the GPL or the LGPL.
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
@ -74,10 +75,13 @@ NS_IMETHODIMP
|
|||
nsArray::IndexOf(PRUint32 aStartIndex, nsISupports* aElement,
|
||||
PRUint32* aResult)
|
||||
{
|
||||
// optimize for the common case by forwarding to mArray
|
||||
if (aStartIndex == 0) {
|
||||
*aResult = mArray.IndexOf(aElement);
|
||||
if (*aResult == -1)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
NS_ADDREF(*aResult);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,37 +1,38 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
* 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.org code.
|
||||
* The Original Code is XPCOM Array implementation.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* The Initial Developer of the Original Code
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Alec Flett <alecf@netscape.com>
|
||||
*
|
||||
* 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
|
||||
* 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 NPL, indicate your
|
||||
* 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 NPL, the GPL or the LGPL.
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
|
|
@ -1,37 +1,38 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
* 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.org code.
|
||||
* The Original Code is a COM aware array class.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Alec Flett <alecf@netscape.com>
|
||||
*
|
||||
* 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
|
||||
* 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 NPL, indicate your
|
||||
* 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 NPL, the GPL or the LGPL.
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
@ -43,53 +44,71 @@ PRBool
|
|||
nsCOMArray_base::InsertObjectAt(nsISupports* aObject, PRInt32 aIndex) {
|
||||
PRBool result = mArray.InsertElementAt(aObject, aIndex);
|
||||
if (result)
|
||||
NS_ADDREF(aObject);
|
||||
NS_IF_ADDREF(aObject);
|
||||
return result;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsCOMArray_base::ReplaceObjectAt(nsISupports* aObject, PRInt32 aIndex) {
|
||||
nsCOMArray_base::ReplaceObjectAt(nsISupports* aObject, PRInt32 aIndex)
|
||||
{
|
||||
nsISupports *oldObject = ObjectAt(aIndex);
|
||||
NS_IF_RELEASE(oldObject);
|
||||
PRBool result = mArray.ReplaceElementAt(aObject, aIndex);
|
||||
if (result)
|
||||
NS_ADDREF(aObject);
|
||||
return result;
|
||||
}
|
||||
if (oldObject) {
|
||||
PRBool result = mArray.ReplaceElementAt(aObject, aIndex);
|
||||
|
||||
|
||||
PRBool
|
||||
nsCOMArray_base::AppendObject(nsISupports *aObject) {
|
||||
PRBool result = InsertObjectAt(aObject, Count());
|
||||
if (result)
|
||||
NS_ADDREF(aObject);
|
||||
return result;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsCOMArray_base::RemoveObject(nsISupports *aObject) {
|
||||
PRBool result = mArray.RemoveElement(aObject);
|
||||
if (result)
|
||||
NS_RELEASE(aObject);
|
||||
return result;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsCOMArray_base::RemoveObjectAt(PRInt32 aIndex) {
|
||||
nsISupports* element = ObjectAt(aIndex);
|
||||
if (element) {
|
||||
PRBool result = mArray.RemoveElementAt(aIndex);
|
||||
if (result)
|
||||
NS_RELEASE(element);
|
||||
// ReplaceElementAt could fail, such as if the array grows
|
||||
// so only release the existing object if the replacement succeeded
|
||||
if (result) {
|
||||
NS_IF_RELEASE(oldObject);
|
||||
NS_IF_ADDREF(aObject);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
nsCOMArray_base::ClearObjectsCallback(void* aElement, void*)
|
||||
nsCOMArray_base::AppendObject(nsISupports *aObject)
|
||||
{
|
||||
PRBool result = InsertObjectAt(aObject, Count());
|
||||
if (result)
|
||||
NS_IF_ADDREF(aObject);
|
||||
return result;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsCOMArray_base::RemoveObject(nsISupports *aObject)
|
||||
{
|
||||
PRBool result = mArray.RemoveElement(aObject);
|
||||
if (result)
|
||||
NS_IF_RELEASE(aObject);
|
||||
return result;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsCOMArray_base::RemoveObjectAt(PRInt32 aIndex)
|
||||
{
|
||||
nsISupports* element = ObjectAt(aIndex);
|
||||
if (element) {
|
||||
PRBool result = mArray.RemoveElementAt(aIndex);
|
||||
if (result)
|
||||
NS_IF_RELEASE(element);
|
||||
return result;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
static PRBool
|
||||
ClearObjectsCallback(void* aElement, void*)
|
||||
{
|
||||
nsISupports* element = NS_STATIC_CAST(nsISupports*, aElement);
|
||||
NS_RELEASE(element);
|
||||
NS_IF_RELEASE(element);
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
nsCOMArray_base::Clear()
|
||||
{
|
||||
mArray.EnumerateForwards(ClearObjectsCallback, nsnull);
|
||||
mArray.Clear();
|
||||
}
|
||||
|
|
|
@ -1,37 +1,38 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
* 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.org code.
|
||||
* The Original Code is a COM aware array class.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* The Initial Developer of the Original Code
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Alec Flett <alecf@netscape.com>
|
||||
*
|
||||
* 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
|
||||
* 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 NPL, indicate your
|
||||
* 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 NPL, the GPL or the LGPL.
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
@ -62,16 +63,11 @@ protected:
|
|||
}
|
||||
|
||||
// override nsVoidArray stuff so that they can be accessed by
|
||||
// other methods
|
||||
// consumers of nsCOMArray
|
||||
PRInt32 Count() const {
|
||||
return mArray.Count();
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
mArray.EnumerateForwards(ClearObjectsCallback, nsnull);
|
||||
mArray.Clear();
|
||||
}
|
||||
|
||||
PRBool EnumerateForwards(nsVoidArrayEnumFunc aFunc, void* aData) {
|
||||
return mArray.EnumerateForwards(aFunc, aData);
|
||||
}
|
||||
|
@ -79,6 +75,7 @@ protected:
|
|||
// any method which is not a direct forward to mArray should
|
||||
// avoid inline bodies, so that the compiler doesn't inline them
|
||||
// all over the place
|
||||
void Clear();
|
||||
PRBool InsertObjectAt(nsISupports* aObject, PRInt32 aIndex);
|
||||
PRBool ReplaceObjectAt(nsISupports* aObject, PRInt32 aIndex);
|
||||
PRBool AppendObject(nsISupports *aObject);
|
||||
|
@ -87,11 +84,10 @@ protected:
|
|||
|
||||
private:
|
||||
|
||||
static PRBool ClearObjectsCallback(void *aElement, void*);
|
||||
|
||||
// the actual storage
|
||||
nsVoidArray mArray;
|
||||
|
||||
|
||||
// don't implement these, defaults will muck with refcounts!
|
||||
nsCOMArray_base(const nsCOMArray_base& other);
|
||||
nsCOMArray_base& operator=(const nsCOMArray_base& other);
|
||||
};
|
||||
|
@ -157,7 +153,8 @@ class nsCOMArray : protected nsCOMArray_base
|
|||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
// don't implement these!
|
||||
nsCOMArray(const nsCOMArray& other);
|
||||
nsCOMArray& operator=(const nsCOMArray& other);
|
||||
};
|
||||
|
|
|
@ -1,37 +1,38 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
* 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.org code.
|
||||
* The Original Code is XPCOM Array interface.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Alec Flett <alecf@netscape.com>
|
||||
*
|
||||
* 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
|
||||
* 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 NPL, indicate your
|
||||
* 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 NPL, the GPL or the LGPL.
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
@ -106,6 +107,7 @@ interface nsIArray : nsISupports
|
|||
*
|
||||
* @status UNDER_REVIEW
|
||||
*/
|
||||
|
||||
[scriptable, uuid(2cd0b2f8-d4dd-48b8-87ba-b0200501f079)]
|
||||
interface nsIMutableArray : nsIArray
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче