From d96798d50e6256b3c45ba3a9d3e98cee09fb2ee9 Mon Sep 17 00:00:00 2001 From: "bryner%netscape.com" Date: Mon, 19 Aug 2002 03:50:27 +0000 Subject: [PATCH] Get rid of gcc3's numerous warnings about using instead of by creating a new #define, NEW_H, which should be used instead of or . This is so we can continue to support a couple of braindead compilers that don't accept . Bug 155852, r=cls. --- config/mac/DefinesMac.h | 85 ----- configure.in | 9 + content/xul/templates/src/nsTemplateMatch.h | 2 +- .../commandhandler/src/nsCommandParams.cpp | 2 +- layout/base/src/nsIntervalSet.cpp | 2 +- layout/generic/nsIntervalSet.cpp | 2 +- modules/libjar/nsZipArchive.cpp | 2 +- rdf/base/src/nsCompositeDataSource.cpp | 2 +- string/public/nsBufferHandleUtils.h | 186 --------- string/src/nsSlidingString.cpp | 352 ------------------ xpcom/ds/nsCppSharedAllocator.h | 2 +- xpcom/ds/nsFixedSizeAllocator.h | 2 +- xpcom/string/public/nsBufferHandleUtils.h | 186 --------- xpcom/string/src/nsSlidingString.cpp | 352 ------------------ 14 files changed, 17 insertions(+), 1169 deletions(-) diff --git a/config/mac/DefinesMac.h b/config/mac/DefinesMac.h index a108f255f30..e69de29bb2d 100644 --- a/config/mac/DefinesMac.h +++ b/config/mac/DefinesMac.h @@ -1,85 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: NPL 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/ - * - * 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 Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * - * 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 NPL, 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. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef DefinesMac_h_ -#define DefinesMac_h_ - -/* - This is a common prefix file, included for both projects like - NSStdLib and Mozilla. -*/ - -/* enable to start building for Carbon */ -#if TARGET_CARBON -#define PP_Target_Carbon 1 -#define OLDP2C 1 -#endif - -/* Some build-wide Mac-related defines */ -#define macintosh /* macintosh is defined for GUSI */ -#define XP_MAC 1 - -/* We have to do this here because ConditionalMacros.h will be included from - * within OpenTptInternet.h and will stupidly define these to 1 if they - * have not been previously defined. The new PowerPlant (CWPro1) requires that - * this be set to 0. (pinkerton) - */ -#define OLDROUTINENAMES 0 -#ifndef OLDROUTINELOCATIONS -#define OLDROUTINELOCATIONS 0 -#endif - -/* We used to define OTUNIXERRORS so that OpenTransport.h would define these errors - * We can't do this with CW 7 because it causes conflict with definitions in - * errno.h. - */ -//#define OTUNIXERRORS 1 - -#ifdef DEBUG -#define DEVELOPER_DEBUG 1 -#else -#define NDEBUG -#endif - -/* Some other random defines */ -#define _NO_FAST_STRING_INLINES_ 1 -#define _PR_NO_PREEMPT 1 -///#define HAVE_BOOLEAN 1 // used by JPEG lib -#define CPP_THROW_NEW throw() - -#endif /* DefinesMac_h_ */ diff --git a/configure.in b/configure.in index b3696210d49..bc7005587fe 100644 --- a/configure.in +++ b/configure.in @@ -959,6 +959,7 @@ case "$target" in AC_DEFINE_UNQUOTED(WINVER,0x400) AC_DEFINE(MSVC4) AC_DEFINE(STDC_HEADERS) + AC_DEFINE(NEW_H, ) TARGET_MD_ARCH=win32 _PLATFORM_DEFAULT_TOOLKIT='windows' BIN_SUFFIX='.exe' @@ -1615,6 +1616,14 @@ AC_CHECK_HEADERS(X11/XKBlib.h) dnl These are all the places some variant of statfs can be hiding. AC_CHECK_HEADERS(sys/statvfs.h sys/statfs.h sys/vfs.h sys/mount.h) +dnl Check whether the compiler supports the new-style C++ standard +dnl library headers (i.e. ) or needs the old "new.h" +AC_LANG_CPLUSPLUS +NEW_H=new.h +AC_CHECK_HEADER(new, [NEW_H=new]) +AC_DEFINE_UNQUOTED(NEW_H, <$NEW_H>) +AC_LANG_C + case $target in *-aix4.3*|*-aix5*) ;; diff --git a/content/xul/templates/src/nsTemplateMatch.h b/content/xul/templates/src/nsTemplateMatch.h index b2d0a9c7234..acbd7988e6b 100644 --- a/content/xul/templates/src/nsTemplateMatch.h +++ b/content/xul/templates/src/nsTemplateMatch.h @@ -43,7 +43,7 @@ #include "nsFixedSizeAllocator.h" #include "nsResourceSet.h" #include "nsRuleNetwork.h" -#include +#include NEW_H /** * A "match" is a fully instantiated rule; that is, a complete and diff --git a/embedding/components/commandhandler/src/nsCommandParams.cpp b/embedding/components/commandhandler/src/nsCommandParams.cpp index 92c8b9bc0d3..ba95763e95e 100644 --- a/embedding/components/commandhandler/src/nsCommandParams.cpp +++ b/embedding/components/commandhandler/src/nsCommandParams.cpp @@ -36,7 +36,7 @@ * * ***** END LICENSE BLOCK ***** */ -#include // for placement new +#include NEW_H // for placement new #include "nscore.h" #include "nsCRT.h" diff --git a/layout/base/src/nsIntervalSet.cpp b/layout/base/src/nsIntervalSet.cpp index 32cffc0d0b7..e4199d61383 100644 --- a/layout/base/src/nsIntervalSet.cpp +++ b/layout/base/src/nsIntervalSet.cpp @@ -37,7 +37,7 @@ * ***** END LICENSE BLOCK ***** */ #include "nsIntervalSet.h" -#include +#include NEW_H nsIntervalSet::nsIntervalSet(IntervalSetAlloc aAlloc, IntervalSetFree aFree, void* aAllocatorClosure) diff --git a/layout/generic/nsIntervalSet.cpp b/layout/generic/nsIntervalSet.cpp index 32cffc0d0b7..e4199d61383 100644 --- a/layout/generic/nsIntervalSet.cpp +++ b/layout/generic/nsIntervalSet.cpp @@ -37,7 +37,7 @@ * ***** END LICENSE BLOCK ***** */ #include "nsIntervalSet.h" -#include +#include NEW_H nsIntervalSet::nsIntervalSet(IntervalSetAlloc aAlloc, IntervalSetFree aFree, void* aAllocatorClosure) diff --git a/modules/libjar/nsZipArchive.cpp b/modules/libjar/nsZipArchive.cpp index cfbcc5ed3e3..51762fb31c9 100644 --- a/modules/libjar/nsZipArchive.cpp +++ b/modules/libjar/nsZipArchive.cpp @@ -57,7 +57,7 @@ nsRecyclingAllocator *gZlibAllocator = NULL; // For placement new used for arena allocations of zip file list -#include +#include NEW_H #else /* STANDALONE */ diff --git a/rdf/base/src/nsCompositeDataSource.cpp b/rdf/base/src/nsCompositeDataSource.cpp index 0c61e6865dc..2651d19929d 100644 --- a/rdf/base/src/nsCompositeDataSource.cpp +++ b/rdf/base/src/nsCompositeDataSource.cpp @@ -61,7 +61,7 @@ */ -#include +#include NEW_H #include "nsCOMPtr.h" #include "nsIComponentManager.h" #include "nsIEnumerator.h" diff --git a/string/public/nsBufferHandleUtils.h b/string/public/nsBufferHandleUtils.h index 52d396327e0..e69de29bb2d 100644 --- a/string/public/nsBufferHandleUtils.h +++ b/string/public/nsBufferHandleUtils.h @@ -1,186 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * 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 strings. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 2000 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - * Scott Collins (original author) - * - */ - -#ifndef nsBufferHandleUtils_h___ -#define nsBufferHandleUtils_h___ - -#ifndef nsAString_h___ -#include "nsAString.h" -#endif - -#ifndef nsStringTraits_h___ -#include "nsStringTraits.h" -#endif - -#include - // for placement |new| - - -template -class nsAutoBufferHandle - { - public: - nsAutoBufferHandle() : mHandle(0) { } - - nsAutoBufferHandle( const nsAutoBufferHandle& aOther ) - : mHandle(aOther.get()) - { - if ( mHandle ) - mHandle->AcquireReference(); - } - - explicit - nsAutoBufferHandle( const nsSharedBufferHandle* aHandle ) - : mHandle( NS_CONST_CAST(nsSharedBufferHandle*, aHandle) ) - { - if ( mHandle ) - mHandle->AcquireReference(); - } - - ~nsAutoBufferHandle() - { - if ( mHandle ) - mHandle->ReleaseReference(); - } - - nsAutoBufferHandle& - operator=( const nsSharedBufferHandle* rhs ) - { - nsSharedBufferHandle* old_handle = mHandle; - if ( (mHandle = NS_CONST_CAST(nsSharedBufferHandle*, rhs)) ) - mHandle->AcquireReference(); - if ( old_handle ) - old_handle->ReleaseReference(); - return *this; - } - - nsAutoBufferHandle& - operator=( const nsAutoBufferHandle& rhs ) - { - return operator=(rhs.get()); - } - - nsSharedBufferHandle* - get() const - { - return mHandle; - } - - operator nsSharedBufferHandle*() const - { - return get(); - } - - nsSharedBufferHandle* - operator->() const - { - return get(); - } - - private: - nsSharedBufferHandle* mHandle; - }; - - -template -inline -size_t -NS_AlignedHandleSize( const HandleT*, const CharT* ) - { - // figure out the number of bytes needed the |HandleT| part, including padding to correctly align the data part - return ((sizeof(HandleT) + sizeof(CharT) - 1) / sizeof(CharT)) * sizeof(CharT); - } - -template -inline -const CharT* -NS_DataAfterHandle( const HandleT* aHandlePtr, const CharT* aDummyCharTPtr ) - { - typedef const CharT* CharT_ptr; - return CharT_ptr(NS_STATIC_CAST(const unsigned char*, aHandlePtr) + NS_AlignedHandleSize(aHandlePtr, aDummyCharTPtr)); - } - -template -inline -CharT* -NS_DataAfterHandle( HandleT* aHandlePtr, const CharT* aDummyCharTPtr ) - { - typedef CharT* CharT_ptr; - return CharT_ptr(NS_STATIC_CAST(unsigned char*, aHandlePtr) + NS_AlignedHandleSize(aHandlePtr, aDummyCharTPtr)); - } - -template -HandleT* -NS_AllocateContiguousHandleWithData( const HandleT* aDummyHandlePtr, PRUint32 aAdditionalCapacity, const StringT* aDataSource ) - { - typedef typename StringT::char_type char_type; - typedef char_type* char_ptr; - - // figure out the number of bytes needed the |HandleT| part, including padding to correctly align the data part - size_t handle_size = NS_AlignedHandleSize(aDummyHandlePtr, char_ptr(0)); - - // figure out how many |char_type|s wee need to fit in the data part - size_t data_length = aDataSource? aDataSource->Length() : 0; - size_t buffer_length = data_length + aAdditionalCapacity; - - // how many bytes is that (including a zero-terminator so we can claim to be flat)? - size_t buffer_size = buffer_length * sizeof(char_type); - - - HandleT* result = 0; - void* handle_ptr = ::operator new(handle_size + buffer_size); - - if ( handle_ptr ) - { - char_ptr data_start_ptr = char_ptr(NS_STATIC_CAST(unsigned char*, handle_ptr) + handle_size); - char_ptr data_end_ptr = data_start_ptr + data_length; - char_ptr buffer_end_ptr = data_start_ptr + buffer_length; - - char_ptr toBegin = data_start_ptr; - - if ( data_length ) - { - typename StringT::const_iterator fromBegin, fromEnd; - copy_string(aDataSource->BeginReading(fromBegin), aDataSource->EndReading(fromEnd), toBegin); - } - - // and if the caller bothered asking for a buffer bigger than their string, we'll zero-terminate - if ( aAdditionalCapacity > 0 ) - *toBegin = char_type(0); - - result = new (handle_ptr) HandleT(data_start_ptr, data_end_ptr, buffer_end_ptr - data_start_ptr, PR_TRUE); - } - - return result; - } - -template -inline -HandleT* -NS_AllocateContiguousHandleWithData( const HandleT* aDummyHandlePtr, const StringT& aDataSource, PRUint32 aAdditionalCapacity ) - { - return NS_AllocateContiguousHandleWithData(aDummyHandlePtr, aAdditionalCapacity, &aDataSource); - } - -#endif // !defined(nsBufferHandleUtils_h___) diff --git a/string/src/nsSlidingString.cpp b/string/src/nsSlidingString.cpp index 659bdb92cd8..e69de29bb2d 100755 --- a/string/src/nsSlidingString.cpp +++ b/string/src/nsSlidingString.cpp @@ -1,352 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * 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 strings. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 2000 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - * Scott Collins (original author) - * - */ - -#include "nsSlidingString.h" - -#ifndef nsBufferHandleUtils_h___ -#include "nsBufferHandleUtils.h" -#endif - -#include - - - - /** - * |nsSlidingSharedBufferList| - */ - -void -nsSlidingSharedBufferList::DiscardUnreferencedPrefix( Buffer* aRecentlyReleasedBuffer ) - { - if ( aRecentlyReleasedBuffer == mFirstBuffer ) - { - while ( mFirstBuffer && !mFirstBuffer->IsReferenced() ) { - Buffer *buffer = UnlinkBuffer(mFirstBuffer); - if (mFreeProc && !buffer->IsSingleAllocationWithBuffer()) { - (*mFreeProc)(buffer->DataStart(), mClientData); - buffer->DataStart(nsnull); - } - delete buffer; - } - } - } - - - - /** - * |nsSlidingSubstring| - */ - - // copy constructor -nsSlidingSubstring::nsSlidingSubstring( const nsSlidingSubstring& aString ) - : mStart(aString.mStart), - mEnd(aString.mEnd), - mBufferList(aString.mBufferList), - mLength(aString.mLength) - { - acquire_ownership_of_buffer_list(); - } - -nsSlidingSubstring::nsSlidingSubstring( const nsSlidingSubstring& aString, const nsAString::const_iterator& aStart, const nsAString::const_iterator& aEnd ) - : mStart(aStart), - mEnd(aEnd), - mBufferList(aString.mBufferList), - mLength(PRUint32(Position::Distance(mStart, mEnd))) - { - acquire_ownership_of_buffer_list(); - } - -nsSlidingSubstring::nsSlidingSubstring( const nsSlidingString& aString ) - : mStart(aString.mStart), - mEnd(aString.mEnd), - mBufferList(aString.mBufferList), - mLength(aString.mLength) - { - acquire_ownership_of_buffer_list(); - } - -nsSlidingSubstring::nsSlidingSubstring( const nsSlidingString& aString, const nsAString::const_iterator& aStart, const nsAString::const_iterator& aEnd ) - : mStart(aStart), - mEnd(aEnd), - mBufferList(aString.mBufferList), - mLength(PRUint32(Position::Distance(mStart, mEnd))) - { - acquire_ownership_of_buffer_list(); - } - -nsSlidingSubstring::nsSlidingSubstring( nsSlidingSharedBufferList* aBufferList ) - : mBufferList(aBufferList) - { - init_range_from_buffer_list(); - acquire_ownership_of_buffer_list(); - } - -typedef const nsSharedBufferList::Buffer* Buffer_ptr; - -static nsSharedBufferList::Buffer* -AllocateContiguousHandleWithData( Buffer_ptr aDummyHandlePtr, const nsAString& aDataSource ) - { - typedef const PRUnichar* PRUnichar_ptr; - - // figure out the number of bytes needed the |HandleT| part, including padding to correctly align the data part - size_t handle_size = NS_AlignedHandleSize(aDummyHandlePtr, PRUnichar_ptr(0)); - - // figure out how many |CharT|s wee need to fit in the data part - size_t string_length = aDataSource.Length(); - - // how many bytes is that (including a zero-terminator so we can claim to be flat)? - size_t string_size = (string_length+1) * sizeof(PRUnichar); - - - nsSharedBufferList::Buffer* result = 0; - void* handle_ptr = ::operator new(handle_size + string_size); - - if ( handle_ptr ) - { - typedef PRUnichar* PRUnichar_ptr; - PRUnichar* string_start_ptr = PRUnichar_ptr(NS_STATIC_CAST(unsigned char*, handle_ptr) + handle_size); - PRUnichar* string_end_ptr = string_start_ptr + string_length; - - nsAString::const_iterator fromBegin, fromEnd; - PRUnichar* toBegin = string_start_ptr; - copy_string(aDataSource.BeginReading(fromBegin), aDataSource.EndReading(fromEnd), toBegin); - result = new (handle_ptr) nsSharedBufferList::Buffer(string_start_ptr, string_end_ptr, string_end_ptr-string_start_ptr+1, PR_TRUE); - } - - return result; - } - -nsSlidingSubstring::nsSlidingSubstring( const nsAString& aSourceString ) - : mBufferList(new nsSlidingSharedBufferList(AllocateContiguousHandleWithData(Buffer_ptr(0), aSourceString))) - { - init_range_from_buffer_list(); - acquire_ownership_of_buffer_list(); - } - -void -nsSlidingSubstring::Rebind( const nsSlidingSubstring& aString ) - { - aString.acquire_ownership_of_buffer_list(); - release_ownership_of_buffer_list(); - - mStart = aString.mStart; - mEnd = aString.mEnd; - mBufferList = aString.mBufferList; - mLength = aString.mLength; - } - -void -nsSlidingSubstring::Rebind( const nsSlidingSubstring& aString, const nsAString::const_iterator& aStart, const nsAString::const_iterator& aEnd ) - { - release_ownership_of_buffer_list(); - - mStart = aStart; - mEnd = aEnd; - mBufferList = aString.mBufferList; - mLength = PRUint32(Position::Distance(mStart, mEnd)); - - acquire_ownership_of_buffer_list(); - } - -void -nsSlidingSubstring::Rebind( const nsSlidingString& aString ) - { - aString.acquire_ownership_of_buffer_list(); - release_ownership_of_buffer_list(); - - mStart = aString.mStart; - mEnd = aString.mEnd; - mBufferList = aString.mBufferList; - mLength = aString.mLength; - } - -void -nsSlidingSubstring::Rebind( const nsSlidingString& aString, const nsAString::const_iterator& aStart, const nsAString::const_iterator& aEnd ) - { - release_ownership_of_buffer_list(); - - mStart = aStart; - mEnd = aEnd; - mBufferList = aString.mBufferList; - mLength = PRUint32(Position::Distance(mStart, mEnd)); - - acquire_ownership_of_buffer_list(); - } - -void -nsSlidingSubstring::Rebind( const nsAString& aSourceString ) - { - release_ownership_of_buffer_list(); - mBufferList = new nsSlidingSharedBufferList(AllocateContiguousHandleWithData(Buffer_ptr(0), aSourceString)); - init_range_from_buffer_list(); - acquire_ownership_of_buffer_list(); - } - -nsSlidingSubstring::~nsSlidingSubstring() - { - release_ownership_of_buffer_list(); - } - -const PRUnichar* -nsSlidingSubstring::GetReadableFragment( nsReadableFragment& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const - { - const Buffer* result_buffer = 0; - switch ( aRequest ) - { - case kPrevFragment: - { - const Buffer* current_buffer = NS_STATIC_CAST(const Buffer*, aFragment.mFragmentIdentifier); - if ( current_buffer != mStart.mBuffer ) - result_buffer = current_buffer->mPrev; - } - break; - - case kFirstFragment: - result_buffer = mStart.mBuffer; - break; - - case kLastFragment: - result_buffer = mEnd.mBuffer; - break; - - case kNextFragment: - { - const Buffer* current_buffer = NS_STATIC_CAST(const Buffer*, aFragment.mFragmentIdentifier); - if ( current_buffer != mEnd.mBuffer ) - result_buffer = current_buffer->mNext; - } - break; - - case kFragmentAt: - { - // kFragmentAt is going away; we hate this linear search - - PRUint32 N; - result_buffer = mStart.mBuffer; - - while ( result_buffer && (N = PRUint32(result_buffer->DataLength())) < aOffset ) - { - aOffset -= N; - result_buffer = result_buffer->mNext; - } - } - break; - } - - if ( result_buffer ) - { - if ( result_buffer == mStart.mBuffer ) - aFragment.mStart = mStart.mPosInBuffer; - else - aFragment.mStart = result_buffer->DataStart(); - - if ( result_buffer == mEnd.mBuffer ) - aFragment.mEnd = mEnd.mPosInBuffer; - else - aFragment.mEnd = result_buffer->DataEnd(); - - aFragment.mFragmentIdentifier = result_buffer; - return aFragment.mStart + aOffset; - } - - return 0; - } - - - - /** - * |nsSlidingString| - */ - -nsSlidingString::nsSlidingString( PRUnichar* aStorageStart, PRUnichar* aDataEnd, PRUnichar* aStorageEnd ) - : nsSlidingSubstring(new nsSlidingSharedBufferList(nsSlidingSharedBufferList::NewWrappingBuffer(aStorageStart, aDataEnd, aStorageEnd))) - { - // nothing else to do here - } - -nsSlidingString::nsSlidingString( PRUnichar* aStorageStart, PRUnichar* aDataEnd, PRUnichar* aStorageEnd, - nsFreeProc *aFreeProc, void *aClientData ) - : nsSlidingSubstring(new nsSlidingSharedBufferList(nsSlidingSharedBufferList::NewWrappingBuffer(aStorageStart, aDataEnd, aStorageEnd), aFreeProc, aClientData)) - { - // nothing else to do here - } - -void -nsSlidingString::AppendBuffer( PRUnichar* aStorageStart, PRUnichar* aDataEnd, PRUnichar* aStorageEnd ) - { - Buffer* new_buffer = - new Buffer(aStorageStart, aDataEnd, aStorageEnd - aStorageStart); - Buffer* old_last_buffer = mBufferList->GetLastBuffer(); - mBufferList->LinkBuffer(old_last_buffer, new_buffer, 0); - mLength += new_buffer->DataLength(); - - mEnd.PointAfter(new_buffer); - } - -void -nsSlidingString::InsertReadable( const nsAString& aReadable, const nsAString::const_iterator& aInsertPoint ) - /* - * Warning: this routine manipulates the shared buffer list in an unexpected way. - * The original design did not really allow for insertions, but this call promises - * that if called for a point after the end of all extant token strings, that no token string - * or the work string will be invalidated. - * - * This routine is protected because it is the responsibility of the derived class to keep those promises. - */ - { - Position insertPos(aInsertPoint); - - mBufferList->SplitBuffer(insertPos, nsSharedBufferList::kSplitCopyRightData); - // splitting to the right keeps the work string and any extant token pointing to and - // holding a reference count on the same buffer - - Buffer* new_buffer = nsSharedBufferList::NewSingleAllocationBuffer(aReadable, 0); - // make a new buffer with all the data to insert... - // BULLSHIT ALERT: we may have empty space to re-use in the split buffer, measure the cost - // of this and decide if we should do the work to fill it - - Buffer* buffer_to_split = insertPos.mBuffer; - mBufferList->LinkBuffer(buffer_to_split, new_buffer, buffer_to_split->mNext); - mLength += aReadable.Length(); - mEnd.PointAfter(mBufferList->GetLastBuffer()); - } - -void -nsSlidingString::DiscardPrefix( const nsAString::const_iterator& aIter ) - { - Position old_start(mStart); - mStart = aIter; - mLength -= Position::Distance(old_start, mStart); - - mStart.mBuffer->AcquireNonOwningReference(); - old_start.mBuffer->ReleaseNonOwningReference(); - - mBufferList->DiscardUnreferencedPrefix(old_start.mBuffer); - } - -const PRUnichar* -nsSlidingString::GetReadableFragment( nsReadableFragment& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const - { - return nsSlidingSubstring::GetReadableFragment(aFragment, aRequest, aOffset); - } diff --git a/xpcom/ds/nsCppSharedAllocator.h b/xpcom/ds/nsCppSharedAllocator.h index 182751f9747..55f3e19db64 100644 --- a/xpcom/ds/nsCppSharedAllocator.h +++ b/xpcom/ds/nsCppSharedAllocator.h @@ -3,7 +3,7 @@ #include "nsMemory.h" // for |nsMemory| #include "nscore.h" // for |NS_XXX_CAST| -#include // to allow placement |new| +#include NEW_H // to allow placement |new| // under Metrowerks (Mac), we don't have autoconf yet diff --git a/xpcom/ds/nsFixedSizeAllocator.h b/xpcom/ds/nsFixedSizeAllocator.h index dfc1fa17eca..76c7324e354 100644 --- a/xpcom/ds/nsFixedSizeAllocator.h +++ b/xpcom/ds/nsFixedSizeAllocator.h @@ -48,7 +48,7 @@ Here is a typical usage pattern: - #include // You'll need this! + #include NEW_H // You'll need this! #include "nsFixedSizeAllocator.h" // Say this is the object you want to allocate a ton of diff --git a/xpcom/string/public/nsBufferHandleUtils.h b/xpcom/string/public/nsBufferHandleUtils.h index 52d396327e0..e69de29bb2d 100644 --- a/xpcom/string/public/nsBufferHandleUtils.h +++ b/xpcom/string/public/nsBufferHandleUtils.h @@ -1,186 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * 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 strings. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 2000 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - * Scott Collins (original author) - * - */ - -#ifndef nsBufferHandleUtils_h___ -#define nsBufferHandleUtils_h___ - -#ifndef nsAString_h___ -#include "nsAString.h" -#endif - -#ifndef nsStringTraits_h___ -#include "nsStringTraits.h" -#endif - -#include - // for placement |new| - - -template -class nsAutoBufferHandle - { - public: - nsAutoBufferHandle() : mHandle(0) { } - - nsAutoBufferHandle( const nsAutoBufferHandle& aOther ) - : mHandle(aOther.get()) - { - if ( mHandle ) - mHandle->AcquireReference(); - } - - explicit - nsAutoBufferHandle( const nsSharedBufferHandle* aHandle ) - : mHandle( NS_CONST_CAST(nsSharedBufferHandle*, aHandle) ) - { - if ( mHandle ) - mHandle->AcquireReference(); - } - - ~nsAutoBufferHandle() - { - if ( mHandle ) - mHandle->ReleaseReference(); - } - - nsAutoBufferHandle& - operator=( const nsSharedBufferHandle* rhs ) - { - nsSharedBufferHandle* old_handle = mHandle; - if ( (mHandle = NS_CONST_CAST(nsSharedBufferHandle*, rhs)) ) - mHandle->AcquireReference(); - if ( old_handle ) - old_handle->ReleaseReference(); - return *this; - } - - nsAutoBufferHandle& - operator=( const nsAutoBufferHandle& rhs ) - { - return operator=(rhs.get()); - } - - nsSharedBufferHandle* - get() const - { - return mHandle; - } - - operator nsSharedBufferHandle*() const - { - return get(); - } - - nsSharedBufferHandle* - operator->() const - { - return get(); - } - - private: - nsSharedBufferHandle* mHandle; - }; - - -template -inline -size_t -NS_AlignedHandleSize( const HandleT*, const CharT* ) - { - // figure out the number of bytes needed the |HandleT| part, including padding to correctly align the data part - return ((sizeof(HandleT) + sizeof(CharT) - 1) / sizeof(CharT)) * sizeof(CharT); - } - -template -inline -const CharT* -NS_DataAfterHandle( const HandleT* aHandlePtr, const CharT* aDummyCharTPtr ) - { - typedef const CharT* CharT_ptr; - return CharT_ptr(NS_STATIC_CAST(const unsigned char*, aHandlePtr) + NS_AlignedHandleSize(aHandlePtr, aDummyCharTPtr)); - } - -template -inline -CharT* -NS_DataAfterHandle( HandleT* aHandlePtr, const CharT* aDummyCharTPtr ) - { - typedef CharT* CharT_ptr; - return CharT_ptr(NS_STATIC_CAST(unsigned char*, aHandlePtr) + NS_AlignedHandleSize(aHandlePtr, aDummyCharTPtr)); - } - -template -HandleT* -NS_AllocateContiguousHandleWithData( const HandleT* aDummyHandlePtr, PRUint32 aAdditionalCapacity, const StringT* aDataSource ) - { - typedef typename StringT::char_type char_type; - typedef char_type* char_ptr; - - // figure out the number of bytes needed the |HandleT| part, including padding to correctly align the data part - size_t handle_size = NS_AlignedHandleSize(aDummyHandlePtr, char_ptr(0)); - - // figure out how many |char_type|s wee need to fit in the data part - size_t data_length = aDataSource? aDataSource->Length() : 0; - size_t buffer_length = data_length + aAdditionalCapacity; - - // how many bytes is that (including a zero-terminator so we can claim to be flat)? - size_t buffer_size = buffer_length * sizeof(char_type); - - - HandleT* result = 0; - void* handle_ptr = ::operator new(handle_size + buffer_size); - - if ( handle_ptr ) - { - char_ptr data_start_ptr = char_ptr(NS_STATIC_CAST(unsigned char*, handle_ptr) + handle_size); - char_ptr data_end_ptr = data_start_ptr + data_length; - char_ptr buffer_end_ptr = data_start_ptr + buffer_length; - - char_ptr toBegin = data_start_ptr; - - if ( data_length ) - { - typename StringT::const_iterator fromBegin, fromEnd; - copy_string(aDataSource->BeginReading(fromBegin), aDataSource->EndReading(fromEnd), toBegin); - } - - // and if the caller bothered asking for a buffer bigger than their string, we'll zero-terminate - if ( aAdditionalCapacity > 0 ) - *toBegin = char_type(0); - - result = new (handle_ptr) HandleT(data_start_ptr, data_end_ptr, buffer_end_ptr - data_start_ptr, PR_TRUE); - } - - return result; - } - -template -inline -HandleT* -NS_AllocateContiguousHandleWithData( const HandleT* aDummyHandlePtr, const StringT& aDataSource, PRUint32 aAdditionalCapacity ) - { - return NS_AllocateContiguousHandleWithData(aDummyHandlePtr, aAdditionalCapacity, &aDataSource); - } - -#endif // !defined(nsBufferHandleUtils_h___) diff --git a/xpcom/string/src/nsSlidingString.cpp b/xpcom/string/src/nsSlidingString.cpp index 659bdb92cd8..e69de29bb2d 100755 --- a/xpcom/string/src/nsSlidingString.cpp +++ b/xpcom/string/src/nsSlidingString.cpp @@ -1,352 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* - * 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 strings. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 2000 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - * Scott Collins (original author) - * - */ - -#include "nsSlidingString.h" - -#ifndef nsBufferHandleUtils_h___ -#include "nsBufferHandleUtils.h" -#endif - -#include - - - - /** - * |nsSlidingSharedBufferList| - */ - -void -nsSlidingSharedBufferList::DiscardUnreferencedPrefix( Buffer* aRecentlyReleasedBuffer ) - { - if ( aRecentlyReleasedBuffer == mFirstBuffer ) - { - while ( mFirstBuffer && !mFirstBuffer->IsReferenced() ) { - Buffer *buffer = UnlinkBuffer(mFirstBuffer); - if (mFreeProc && !buffer->IsSingleAllocationWithBuffer()) { - (*mFreeProc)(buffer->DataStart(), mClientData); - buffer->DataStart(nsnull); - } - delete buffer; - } - } - } - - - - /** - * |nsSlidingSubstring| - */ - - // copy constructor -nsSlidingSubstring::nsSlidingSubstring( const nsSlidingSubstring& aString ) - : mStart(aString.mStart), - mEnd(aString.mEnd), - mBufferList(aString.mBufferList), - mLength(aString.mLength) - { - acquire_ownership_of_buffer_list(); - } - -nsSlidingSubstring::nsSlidingSubstring( const nsSlidingSubstring& aString, const nsAString::const_iterator& aStart, const nsAString::const_iterator& aEnd ) - : mStart(aStart), - mEnd(aEnd), - mBufferList(aString.mBufferList), - mLength(PRUint32(Position::Distance(mStart, mEnd))) - { - acquire_ownership_of_buffer_list(); - } - -nsSlidingSubstring::nsSlidingSubstring( const nsSlidingString& aString ) - : mStart(aString.mStart), - mEnd(aString.mEnd), - mBufferList(aString.mBufferList), - mLength(aString.mLength) - { - acquire_ownership_of_buffer_list(); - } - -nsSlidingSubstring::nsSlidingSubstring( const nsSlidingString& aString, const nsAString::const_iterator& aStart, const nsAString::const_iterator& aEnd ) - : mStart(aStart), - mEnd(aEnd), - mBufferList(aString.mBufferList), - mLength(PRUint32(Position::Distance(mStart, mEnd))) - { - acquire_ownership_of_buffer_list(); - } - -nsSlidingSubstring::nsSlidingSubstring( nsSlidingSharedBufferList* aBufferList ) - : mBufferList(aBufferList) - { - init_range_from_buffer_list(); - acquire_ownership_of_buffer_list(); - } - -typedef const nsSharedBufferList::Buffer* Buffer_ptr; - -static nsSharedBufferList::Buffer* -AllocateContiguousHandleWithData( Buffer_ptr aDummyHandlePtr, const nsAString& aDataSource ) - { - typedef const PRUnichar* PRUnichar_ptr; - - // figure out the number of bytes needed the |HandleT| part, including padding to correctly align the data part - size_t handle_size = NS_AlignedHandleSize(aDummyHandlePtr, PRUnichar_ptr(0)); - - // figure out how many |CharT|s wee need to fit in the data part - size_t string_length = aDataSource.Length(); - - // how many bytes is that (including a zero-terminator so we can claim to be flat)? - size_t string_size = (string_length+1) * sizeof(PRUnichar); - - - nsSharedBufferList::Buffer* result = 0; - void* handle_ptr = ::operator new(handle_size + string_size); - - if ( handle_ptr ) - { - typedef PRUnichar* PRUnichar_ptr; - PRUnichar* string_start_ptr = PRUnichar_ptr(NS_STATIC_CAST(unsigned char*, handle_ptr) + handle_size); - PRUnichar* string_end_ptr = string_start_ptr + string_length; - - nsAString::const_iterator fromBegin, fromEnd; - PRUnichar* toBegin = string_start_ptr; - copy_string(aDataSource.BeginReading(fromBegin), aDataSource.EndReading(fromEnd), toBegin); - result = new (handle_ptr) nsSharedBufferList::Buffer(string_start_ptr, string_end_ptr, string_end_ptr-string_start_ptr+1, PR_TRUE); - } - - return result; - } - -nsSlidingSubstring::nsSlidingSubstring( const nsAString& aSourceString ) - : mBufferList(new nsSlidingSharedBufferList(AllocateContiguousHandleWithData(Buffer_ptr(0), aSourceString))) - { - init_range_from_buffer_list(); - acquire_ownership_of_buffer_list(); - } - -void -nsSlidingSubstring::Rebind( const nsSlidingSubstring& aString ) - { - aString.acquire_ownership_of_buffer_list(); - release_ownership_of_buffer_list(); - - mStart = aString.mStart; - mEnd = aString.mEnd; - mBufferList = aString.mBufferList; - mLength = aString.mLength; - } - -void -nsSlidingSubstring::Rebind( const nsSlidingSubstring& aString, const nsAString::const_iterator& aStart, const nsAString::const_iterator& aEnd ) - { - release_ownership_of_buffer_list(); - - mStart = aStart; - mEnd = aEnd; - mBufferList = aString.mBufferList; - mLength = PRUint32(Position::Distance(mStart, mEnd)); - - acquire_ownership_of_buffer_list(); - } - -void -nsSlidingSubstring::Rebind( const nsSlidingString& aString ) - { - aString.acquire_ownership_of_buffer_list(); - release_ownership_of_buffer_list(); - - mStart = aString.mStart; - mEnd = aString.mEnd; - mBufferList = aString.mBufferList; - mLength = aString.mLength; - } - -void -nsSlidingSubstring::Rebind( const nsSlidingString& aString, const nsAString::const_iterator& aStart, const nsAString::const_iterator& aEnd ) - { - release_ownership_of_buffer_list(); - - mStart = aStart; - mEnd = aEnd; - mBufferList = aString.mBufferList; - mLength = PRUint32(Position::Distance(mStart, mEnd)); - - acquire_ownership_of_buffer_list(); - } - -void -nsSlidingSubstring::Rebind( const nsAString& aSourceString ) - { - release_ownership_of_buffer_list(); - mBufferList = new nsSlidingSharedBufferList(AllocateContiguousHandleWithData(Buffer_ptr(0), aSourceString)); - init_range_from_buffer_list(); - acquire_ownership_of_buffer_list(); - } - -nsSlidingSubstring::~nsSlidingSubstring() - { - release_ownership_of_buffer_list(); - } - -const PRUnichar* -nsSlidingSubstring::GetReadableFragment( nsReadableFragment& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const - { - const Buffer* result_buffer = 0; - switch ( aRequest ) - { - case kPrevFragment: - { - const Buffer* current_buffer = NS_STATIC_CAST(const Buffer*, aFragment.mFragmentIdentifier); - if ( current_buffer != mStart.mBuffer ) - result_buffer = current_buffer->mPrev; - } - break; - - case kFirstFragment: - result_buffer = mStart.mBuffer; - break; - - case kLastFragment: - result_buffer = mEnd.mBuffer; - break; - - case kNextFragment: - { - const Buffer* current_buffer = NS_STATIC_CAST(const Buffer*, aFragment.mFragmentIdentifier); - if ( current_buffer != mEnd.mBuffer ) - result_buffer = current_buffer->mNext; - } - break; - - case kFragmentAt: - { - // kFragmentAt is going away; we hate this linear search - - PRUint32 N; - result_buffer = mStart.mBuffer; - - while ( result_buffer && (N = PRUint32(result_buffer->DataLength())) < aOffset ) - { - aOffset -= N; - result_buffer = result_buffer->mNext; - } - } - break; - } - - if ( result_buffer ) - { - if ( result_buffer == mStart.mBuffer ) - aFragment.mStart = mStart.mPosInBuffer; - else - aFragment.mStart = result_buffer->DataStart(); - - if ( result_buffer == mEnd.mBuffer ) - aFragment.mEnd = mEnd.mPosInBuffer; - else - aFragment.mEnd = result_buffer->DataEnd(); - - aFragment.mFragmentIdentifier = result_buffer; - return aFragment.mStart + aOffset; - } - - return 0; - } - - - - /** - * |nsSlidingString| - */ - -nsSlidingString::nsSlidingString( PRUnichar* aStorageStart, PRUnichar* aDataEnd, PRUnichar* aStorageEnd ) - : nsSlidingSubstring(new nsSlidingSharedBufferList(nsSlidingSharedBufferList::NewWrappingBuffer(aStorageStart, aDataEnd, aStorageEnd))) - { - // nothing else to do here - } - -nsSlidingString::nsSlidingString( PRUnichar* aStorageStart, PRUnichar* aDataEnd, PRUnichar* aStorageEnd, - nsFreeProc *aFreeProc, void *aClientData ) - : nsSlidingSubstring(new nsSlidingSharedBufferList(nsSlidingSharedBufferList::NewWrappingBuffer(aStorageStart, aDataEnd, aStorageEnd), aFreeProc, aClientData)) - { - // nothing else to do here - } - -void -nsSlidingString::AppendBuffer( PRUnichar* aStorageStart, PRUnichar* aDataEnd, PRUnichar* aStorageEnd ) - { - Buffer* new_buffer = - new Buffer(aStorageStart, aDataEnd, aStorageEnd - aStorageStart); - Buffer* old_last_buffer = mBufferList->GetLastBuffer(); - mBufferList->LinkBuffer(old_last_buffer, new_buffer, 0); - mLength += new_buffer->DataLength(); - - mEnd.PointAfter(new_buffer); - } - -void -nsSlidingString::InsertReadable( const nsAString& aReadable, const nsAString::const_iterator& aInsertPoint ) - /* - * Warning: this routine manipulates the shared buffer list in an unexpected way. - * The original design did not really allow for insertions, but this call promises - * that if called for a point after the end of all extant token strings, that no token string - * or the work string will be invalidated. - * - * This routine is protected because it is the responsibility of the derived class to keep those promises. - */ - { - Position insertPos(aInsertPoint); - - mBufferList->SplitBuffer(insertPos, nsSharedBufferList::kSplitCopyRightData); - // splitting to the right keeps the work string and any extant token pointing to and - // holding a reference count on the same buffer - - Buffer* new_buffer = nsSharedBufferList::NewSingleAllocationBuffer(aReadable, 0); - // make a new buffer with all the data to insert... - // BULLSHIT ALERT: we may have empty space to re-use in the split buffer, measure the cost - // of this and decide if we should do the work to fill it - - Buffer* buffer_to_split = insertPos.mBuffer; - mBufferList->LinkBuffer(buffer_to_split, new_buffer, buffer_to_split->mNext); - mLength += aReadable.Length(); - mEnd.PointAfter(mBufferList->GetLastBuffer()); - } - -void -nsSlidingString::DiscardPrefix( const nsAString::const_iterator& aIter ) - { - Position old_start(mStart); - mStart = aIter; - mLength -= Position::Distance(old_start, mStart); - - mStart.mBuffer->AcquireNonOwningReference(); - old_start.mBuffer->ReleaseNonOwningReference(); - - mBufferList->DiscardUnreferencedPrefix(old_start.mBuffer); - } - -const PRUnichar* -nsSlidingString::GetReadableFragment( nsReadableFragment& aFragment, nsFragmentRequest aRequest, PRUint32 aOffset ) const - { - return nsSlidingSubstring::GetReadableFragment(aFragment, aRequest, aOffset); - }