2014-05-05 21:30:46 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define ENABLE_STRING_STATS
|
|
|
|
#endif
|
|
|
|
|
2013-08-22 19:14:42 +04:00
|
|
|
#include "mozilla/Atomics.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
|
|
|
|
2004-02-19 05:44:03 +03:00
|
|
|
#ifdef ENABLE_STRING_STATS
|
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "nsSubstring.h"
|
|
|
|
#include "nsString.h"
|
2005-02-03 01:18:37 +03:00
|
|
|
#include "nsStringBuffer.h"
|
2004-02-19 05:44:03 +03:00
|
|
|
#include "nsDependentString.h"
|
|
|
|
#include "nsMemory.h"
|
2009-11-05 00:33:23 +03:00
|
|
|
#include "prprf.h"
|
2010-03-08 18:44:59 +03:00
|
|
|
#include "nsStaticAtom.h"
|
2013-04-22 15:13:22 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2013-11-21 23:17:35 +04:00
|
|
|
#include "mozilla/IntegerPrintfMacros.h"
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <windows.h>
|
|
|
|
#include <process.h>
|
|
|
|
#define getpid() _getpid()
|
|
|
|
#define pthread_self() GetCurrentThreadId()
|
|
|
|
#else
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2013-08-22 19:14:42 +04:00
|
|
|
using mozilla::Atomic;
|
|
|
|
|
2004-02-19 05:44:03 +03:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2014-02-03 16:27:56 +04:00
|
|
|
static const char16_t gNullChar = 0;
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-02-03 16:27:56 +04:00
|
|
|
char* const nsCharTraits<char>::sEmptyBuffer =
|
2014-05-27 11:15:35 +04:00
|
|
|
(char*)const_cast<char16_t*>(&gNullChar);
|
2014-02-03 16:27:56 +04:00
|
|
|
char16_t* const nsCharTraits<char16_t>::sEmptyBuffer =
|
|
|
|
const_cast<char16_t*>(&gNullChar);
|
2004-02-19 05:44:03 +03:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#ifdef ENABLE_STRING_STATS
|
|
|
|
class nsStringStats
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsStringStats()
|
2014-05-27 11:15:35 +04:00
|
|
|
: mAllocCount(0)
|
|
|
|
, mReallocCount(0)
|
|
|
|
, mFreeCount(0)
|
|
|
|
, mShareCount(0)
|
|
|
|
{
|
|
|
|
}
|
2014-05-05 21:30:46 +04:00
|
|
|
|
|
|
|
~nsStringStats()
|
2004-02-19 05:44:03 +03:00
|
|
|
{
|
2014-05-05 21:30:46 +04:00
|
|
|
// this is a hack to suppress duplicate string stats printing
|
|
|
|
// in seamonkey as a result of the string code being linked
|
|
|
|
// into seamonkey and libxpcom! :-(
|
2014-05-27 11:15:35 +04:00
|
|
|
if (!mAllocCount && !mAdoptCount) {
|
2014-05-05 21:30:46 +04:00
|
|
|
return;
|
2014-05-27 11:15:35 +04:00
|
|
|
}
|
2014-05-05 21:30:46 +04:00
|
|
|
|
|
|
|
printf("nsStringStats\n");
|
|
|
|
printf(" => mAllocCount: % 10d\n", int(mAllocCount));
|
|
|
|
printf(" => mReallocCount: % 10d\n", int(mReallocCount));
|
|
|
|
printf(" => mFreeCount: % 10d", int(mFreeCount));
|
2014-05-27 11:15:35 +04:00
|
|
|
if (mAllocCount > mFreeCount) {
|
2014-05-05 21:30:46 +04:00
|
|
|
printf(" -- LEAKED %d !!!\n", mAllocCount - mFreeCount);
|
2014-05-27 11:15:35 +04:00
|
|
|
} else {
|
2014-05-05 21:30:46 +04:00
|
|
|
printf("\n");
|
2014-05-27 11:15:35 +04:00
|
|
|
}
|
2014-05-05 21:30:46 +04:00
|
|
|
printf(" => mShareCount: % 10d\n", int(mShareCount));
|
|
|
|
printf(" => mAdoptCount: % 10d\n", int(mAdoptCount));
|
|
|
|
printf(" => mAdoptFreeCount: % 10d", int(mAdoptFreeCount));
|
2014-05-27 11:15:35 +04:00
|
|
|
if (mAdoptCount > mAdoptFreeCount) {
|
2014-05-05 21:30:46 +04:00
|
|
|
printf(" -- LEAKED %d !!!\n", mAdoptCount - mAdoptFreeCount);
|
2014-05-27 11:15:35 +04:00
|
|
|
} else {
|
2014-05-05 21:30:46 +04:00
|
|
|
printf("\n");
|
2014-05-27 11:15:35 +04:00
|
|
|
}
|
2014-05-05 21:30:46 +04:00
|
|
|
printf(" => Process ID: %" PRIuPTR ", Thread ID: %" PRIuPTR "\n",
|
|
|
|
uintptr_t(getpid()), uintptr_t(pthread_self()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Atomic<int32_t> mAllocCount;
|
|
|
|
Atomic<int32_t> mReallocCount;
|
|
|
|
Atomic<int32_t> mFreeCount;
|
|
|
|
Atomic<int32_t> mShareCount;
|
|
|
|
Atomic<int32_t> mAdoptCount;
|
|
|
|
Atomic<int32_t> mAdoptFreeCount;
|
|
|
|
};
|
2004-02-19 05:44:03 +03:00
|
|
|
static nsStringStats gStringStats;
|
2013-08-22 19:14:42 +04:00
|
|
|
#define STRING_STAT_INCREMENT(_s) (gStringStats.m ## _s ## Count)++
|
2004-02-19 05:44:03 +03:00
|
|
|
#else
|
|
|
|
#define STRING_STAT_INCREMENT(_s)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2014-12-13 02:57:09 +03:00
|
|
|
void
|
2014-05-27 11:15:35 +04:00
|
|
|
ReleaseData(void* aData, uint32_t aFlags)
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2014-05-27 11:15:35 +04:00
|
|
|
if (aFlags & nsSubstring::F_SHARED) {
|
|
|
|
nsStringBuffer::FromData(aData)->Release();
|
|
|
|
} else if (aFlags & nsSubstring::F_OWNED) {
|
2015-03-27 03:01:12 +03:00
|
|
|
free(aData);
|
2014-05-05 21:30:46 +04:00
|
|
|
STRING_STAT_INCREMENT(AdoptFree);
|
|
|
|
// Treat this as destruction of a "StringAdopt" object for leak
|
|
|
|
// tracking purposes.
|
2015-04-03 16:52:00 +03:00
|
|
|
MOZ_LOG_DTOR(aData, "StringAdopt", 1);
|
2005-02-03 01:18:37 +03:00
|
|
|
}
|
2014-05-05 21:30:46 +04:00
|
|
|
// otherwise, nothing to do.
|
|
|
|
}
|
2005-02-03 01:18:37 +03:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2005-02-03 01:18:37 +03:00
|
|
|
// XXX or we could make nsStringBuffer be a friend of nsTAString
|
|
|
|
|
|
|
|
class nsAStringAccessor : public nsAString
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
nsAStringAccessor(); // NOT IMPLEMENTED
|
|
|
|
|
|
|
|
public:
|
2014-05-27 11:15:35 +04:00
|
|
|
char_type* data() const
|
|
|
|
{
|
|
|
|
return mData;
|
|
|
|
}
|
|
|
|
size_type length() const
|
|
|
|
{
|
|
|
|
return mLength;
|
|
|
|
}
|
|
|
|
uint32_t flags() const
|
|
|
|
{
|
|
|
|
return mFlags;
|
|
|
|
}
|
2014-05-05 21:30:46 +04:00
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
void set(char_type* aData, size_type aLen, uint32_t aFlags)
|
2005-02-03 01:18:37 +03:00
|
|
|
{
|
2014-05-05 21:30:46 +04:00
|
|
|
ReleaseData(mData, mFlags);
|
2014-05-27 11:15:35 +04:00
|
|
|
mData = aData;
|
|
|
|
mLength = aLen;
|
|
|
|
mFlags = aFlags;
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
|
|
|
};
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2005-02-03 01:18:37 +03:00
|
|
|
class nsACStringAccessor : public nsACString
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
nsACStringAccessor(); // NOT IMPLEMENTED
|
|
|
|
|
|
|
|
public:
|
2014-05-27 11:15:35 +04:00
|
|
|
char_type* data() const
|
|
|
|
{
|
|
|
|
return mData;
|
|
|
|
}
|
|
|
|
size_type length() const
|
|
|
|
{
|
|
|
|
return mLength;
|
|
|
|
}
|
|
|
|
uint32_t flags() const
|
|
|
|
{
|
|
|
|
return mFlags;
|
|
|
|
}
|
2014-05-05 21:30:46 +04:00
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
void set(char_type* aData, size_type aLen, uint32_t aFlags)
|
2005-02-03 01:18:37 +03:00
|
|
|
{
|
2014-05-05 21:30:46 +04:00
|
|
|
ReleaseData(mData, mFlags);
|
2014-05-27 11:15:35 +04:00
|
|
|
mData = aData;
|
|
|
|
mLength = aLen;
|
|
|
|
mFlags = aFlags;
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
|
|
|
};
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2005-02-03 01:18:37 +03:00
|
|
|
// ---------------------------------------------------------------------------
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2005-02-03 01:18:37 +03:00
|
|
|
void
|
|
|
|
nsStringBuffer::AddRef()
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2017-04-05 06:59:21 +03:00
|
|
|
// Memory synchronization is not required when incrementing a
|
|
|
|
// reference count. The first increment of a reference count on a
|
|
|
|
// thread is not important, since the first use of the object on a
|
|
|
|
// thread can happen before it. What is important is the transfer
|
|
|
|
// of the pointer to that thread, which may happen prior to the
|
|
|
|
// first increment on that thread. The necessary memory
|
|
|
|
// synchronization is done by the mechanism that transfers the
|
|
|
|
// pointer between threads.
|
2017-04-05 07:42:18 +03:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
uint32_t count =
|
|
|
|
#endif
|
|
|
|
mRefCount.fetch_add(1, std::memory_order_relaxed)
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
+ 1
|
|
|
|
#endif
|
|
|
|
;
|
2014-05-05 21:30:46 +04:00
|
|
|
STRING_STAT_INCREMENT(Share);
|
2017-04-05 06:59:21 +03:00
|
|
|
NS_LOG_ADDREF(this, count, "nsStringBuffer", sizeof(*this));
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2005-02-03 01:18:37 +03:00
|
|
|
void
|
|
|
|
nsStringBuffer::Release()
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2017-04-05 06:59:21 +03:00
|
|
|
// Since this may be the last release on this thread, we need
|
|
|
|
// release semantics so that prior writes on this thread are visible
|
|
|
|
// to the thread that destroys the object when it reads mValue with
|
|
|
|
// acquire semantics.
|
|
|
|
uint32_t count = mRefCount.fetch_sub(1, std::memory_order_release) - 1;
|
2014-05-05 21:30:46 +04:00
|
|
|
NS_LOG_RELEASE(this, count, "nsStringBuffer");
|
2014-05-27 11:15:35 +04:00
|
|
|
if (count == 0) {
|
2017-04-05 06:59:21 +03:00
|
|
|
// We're going to destroy the object on this thread, so we need
|
|
|
|
// acquire semantics to synchronize with the memory released by
|
|
|
|
// the last release on other threads, that is, to ensure that
|
|
|
|
// writes prior to that release are now visible on this thread.
|
|
|
|
count = mRefCount.load(std::memory_order_acquire);
|
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
STRING_STAT_INCREMENT(Free);
|
|
|
|
free(this); // we were allocated with |malloc|
|
2005-02-03 01:18:37 +03:00
|
|
|
}
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
/**
|
|
|
|
* Alloc returns a pointer to a new string header with set capacity.
|
|
|
|
*/
|
2013-04-22 15:13:22 +04:00
|
|
|
already_AddRefed<nsStringBuffer>
|
2014-05-27 11:15:35 +04:00
|
|
|
nsStringBuffer::Alloc(size_t aSize)
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2014-05-27 11:15:35 +04:00
|
|
|
NS_ASSERTION(aSize != 0, "zero capacity allocation not allowed");
|
|
|
|
NS_ASSERTION(sizeof(nsStringBuffer) + aSize <= size_t(uint32_t(-1)) &&
|
|
|
|
sizeof(nsStringBuffer) + aSize > aSize,
|
2014-05-05 21:30:46 +04:00
|
|
|
"mStorageSize will truncate");
|
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
nsStringBuffer* hdr =
|
|
|
|
(nsStringBuffer*)malloc(sizeof(nsStringBuffer) + aSize);
|
|
|
|
if (hdr) {
|
2014-05-05 21:30:46 +04:00
|
|
|
STRING_STAT_INCREMENT(Alloc);
|
|
|
|
|
|
|
|
hdr->mRefCount = 1;
|
2014-05-27 11:15:35 +04:00
|
|
|
hdr->mStorageSize = aSize;
|
2014-05-05 21:30:46 +04:00
|
|
|
NS_LOG_ADDREF(hdr, 1, "nsStringBuffer", sizeof(*hdr));
|
2005-02-03 01:18:37 +03:00
|
|
|
}
|
2014-05-05 21:30:46 +04:00
|
|
|
return dont_AddRef(hdr);
|
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2005-02-03 01:18:37 +03:00
|
|
|
nsStringBuffer*
|
2014-05-27 11:15:35 +04:00
|
|
|
nsStringBuffer::Realloc(nsStringBuffer* aHdr, size_t aSize)
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
|
|
|
STRING_STAT_INCREMENT(Realloc);
|
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
NS_ASSERTION(aSize != 0, "zero capacity allocation not allowed");
|
|
|
|
NS_ASSERTION(sizeof(nsStringBuffer) + aSize <= size_t(uint32_t(-1)) &&
|
|
|
|
sizeof(nsStringBuffer) + aSize > aSize,
|
2014-05-05 21:30:46 +04:00
|
|
|
"mStorageSize will truncate");
|
|
|
|
|
|
|
|
// no point in trying to save ourselves if we hit this assertion
|
2014-05-27 11:15:35 +04:00
|
|
|
NS_ASSERTION(!aHdr->IsReadonly(), "|Realloc| attempted on readonly string");
|
2014-05-05 21:30:46 +04:00
|
|
|
|
|
|
|
// Treat this as a release and addref for refcounting purposes, since we
|
|
|
|
// just asserted that the refcount is 1. If we don't do that, refcount
|
|
|
|
// logging will claim we've leaked all sorts of stuff.
|
2014-05-27 11:15:35 +04:00
|
|
|
NS_LOG_RELEASE(aHdr, 0, "nsStringBuffer");
|
2014-05-05 21:30:46 +04:00
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
aHdr = (nsStringBuffer*)realloc(aHdr, sizeof(nsStringBuffer) + aSize);
|
|
|
|
if (aHdr) {
|
|
|
|
NS_LOG_ADDREF(aHdr, 1, "nsStringBuffer", sizeof(*aHdr));
|
|
|
|
aHdr->mStorageSize = aSize;
|
2005-02-03 01:18:37 +03:00
|
|
|
}
|
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
return aHdr;
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
|
|
|
|
2005-02-03 01:18:37 +03:00
|
|
|
nsStringBuffer*
|
2014-05-27 11:15:35 +04:00
|
|
|
nsStringBuffer::FromString(const nsAString& aStr)
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
|
|
|
const nsAStringAccessor* accessor =
|
2014-05-27 11:15:35 +04:00
|
|
|
static_cast<const nsAStringAccessor*>(&aStr);
|
2005-02-03 01:18:37 +03:00
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
if (!(accessor->flags() & nsSubstring::F_SHARED)) {
|
2014-05-05 21:30:46 +04:00
|
|
|
return nullptr;
|
2014-05-27 11:15:35 +04:00
|
|
|
}
|
2005-02-03 01:18:37 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
return FromData(accessor->data());
|
|
|
|
}
|
2005-02-03 01:18:37 +03:00
|
|
|
|
|
|
|
nsStringBuffer*
|
2014-05-27 11:15:35 +04:00
|
|
|
nsStringBuffer::FromString(const nsACString& aStr)
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
|
|
|
const nsACStringAccessor* accessor =
|
2014-05-27 11:15:35 +04:00
|
|
|
static_cast<const nsACStringAccessor*>(&aStr);
|
2005-02-03 01:18:37 +03:00
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
if (!(accessor->flags() & nsCSubstring::F_SHARED)) {
|
2014-05-05 21:30:46 +04:00
|
|
|
return nullptr;
|
2014-05-27 11:15:35 +04:00
|
|
|
}
|
2005-02-03 01:18:37 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
return FromData(accessor->data());
|
|
|
|
}
|
2005-02-03 01:18:37 +03:00
|
|
|
|
|
|
|
void
|
2014-05-27 11:15:35 +04:00
|
|
|
nsStringBuffer::ToString(uint32_t aLen, nsAString& aStr,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aMoveOwnership)
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
|
|
|
char16_t* data = static_cast<char16_t*>(Data());
|
2005-02-03 01:18:37 +03:00
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
nsAStringAccessor* accessor = static_cast<nsAStringAccessor*>(&aStr);
|
2017-01-19 06:20:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(data[aLen] == char16_t(0),
|
|
|
|
"data should be null terminated");
|
2005-02-03 01:18:37 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
// preserve class flags
|
|
|
|
uint32_t flags = accessor->flags();
|
|
|
|
flags = (flags & 0xFFFF0000) | nsSubstring::F_SHARED | nsSubstring::F_TERMINATED;
|
2005-02-03 01:18:37 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
if (!aMoveOwnership) {
|
|
|
|
AddRef();
|
2005-02-03 01:18:37 +03:00
|
|
|
}
|
2014-05-27 11:15:35 +04:00
|
|
|
accessor->set(data, aLen, flags);
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
2005-02-03 01:18:37 +03:00
|
|
|
|
|
|
|
void
|
2014-05-27 11:15:35 +04:00
|
|
|
nsStringBuffer::ToString(uint32_t aLen, nsACString& aStr,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aMoveOwnership)
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
|
|
|
char* data = static_cast<char*>(Data());
|
2005-02-03 01:18:37 +03:00
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
nsACStringAccessor* accessor = static_cast<nsACStringAccessor*>(&aStr);
|
2017-01-19 06:20:15 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(data[aLen] == char(0),
|
|
|
|
"data should be null terminated");
|
2005-02-03 01:18:37 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
// preserve class flags
|
|
|
|
uint32_t flags = accessor->flags();
|
|
|
|
flags = (flags & 0xFFFF0000) | nsCSubstring::F_SHARED | nsCSubstring::F_TERMINATED;
|
2005-02-03 01:18:37 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
if (!aMoveOwnership) {
|
|
|
|
AddRef();
|
2004-02-19 05:44:03 +03:00
|
|
|
}
|
2014-05-27 11:15:35 +04:00
|
|
|
accessor->set(data, aLen, flags);
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2011-12-23 04:57:30 +04:00
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsStringBuffer::SizeOfIncludingThisIfUnshared(mozilla::MallocSizeOf aMallocSizeOf) const
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
2015-12-02 02:36:26 +03:00
|
|
|
return IsReadonly() ? 0 : aMallocSizeOf(this);
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
2011-12-23 04:57:30 +04:00
|
|
|
|
2013-01-18 09:21:35 +04:00
|
|
|
size_t
|
2013-06-23 16:03:39 +04:00
|
|
|
nsStringBuffer::SizeOfIncludingThisEvenIfShared(mozilla::MallocSizeOf aMallocSizeOf) const
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
|
|
|
return aMallocSizeOf(this);
|
|
|
|
}
|
2013-01-18 09:21:35 +04:00
|
|
|
|
2005-02-03 01:18:37 +03:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2004-02-19 05:44:03 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
// define nsSubstring
|
2004-02-19 05:44:03 +03:00
|
|
|
#include "string-template-def-unichar.h"
|
|
|
|
#include "nsTSubstring.cpp"
|
|
|
|
#include "string-template-undef.h"
|
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
// define nsCSubstring
|
2004-02-19 05:44:03 +03:00
|
|
|
#include "string-template-def-char.h"
|
|
|
|
#include "nsTSubstring.cpp"
|
|
|
|
#include "string-template-undef.h"
|
2008-07-30 10:06:54 +04:00
|
|
|
|
2016-08-17 01:05:05 +03:00
|
|
|
// Provide rust bindings to the nsA[C]String types
|
|
|
|
extern "C" {
|
|
|
|
|
2017-02-01 21:30:01 +03:00
|
|
|
// This is a no-op on release, so we ifdef it out such that using it in release
|
|
|
|
// results in a linker error.
|
|
|
|
#ifdef DEBUG
|
2017-01-27 23:12:22 +03:00
|
|
|
void Gecko_IncrementStringAdoptCount(void* aData)
|
|
|
|
{
|
|
|
|
MOZ_LOG_CTOR(aData, "StringAdopt", 1);
|
|
|
|
}
|
Bug 1353810 - add a --enable-rust-debug option; r=chmanchester
For people working on Rust code, compiling in debug mode (Cargo's "dev"
profile) is convenient: debug assertions are turned on, optimization is
turned off, and parallel compilation inside of rustc itself can be
used. These things make the build faster and the debugging experience
more pleasant.
To obtain that currently, one needs to --enable-debug at the Gecko
toplevel, which turns on debug assertions for the entire browser, which
makes things run unreasonably slowly. So it would be desirable to be
able to turn *off* debug mode for the entirety of the browser, but turn
on debug mode for the Rust code only.
Hence this added switch, --enable-rust-debug, which does what it
suggests and defaults to the value of --enable-debug. For our own
sanity and because we judge it a non-existent use case, we do not
support --enable-debug --disable-rust-debug.
2017-04-13 04:49:25 +03:00
|
|
|
#elif defined(MOZ_DEBUG_RUST)
|
|
|
|
void Gecko_IncrementStringAdoptCount(void *aData)
|
|
|
|
{
|
|
|
|
}
|
2017-02-01 21:30:01 +03:00
|
|
|
#endif
|
2017-01-27 23:12:22 +03:00
|
|
|
|
2016-08-17 01:05:05 +03:00
|
|
|
void Gecko_FinalizeCString(nsACString* aThis)
|
|
|
|
{
|
|
|
|
aThis->~nsACString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Gecko_AssignCString(nsACString* aThis, const nsACString* aOther)
|
|
|
|
{
|
|
|
|
aThis->Assign(*aOther);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Gecko_AppendCString(nsACString* aThis, const nsACString* aOther)
|
|
|
|
{
|
|
|
|
aThis->Append(*aOther);
|
|
|
|
}
|
|
|
|
|
2017-03-20 21:40:25 +03:00
|
|
|
void Gecko_SetLengthCString(nsACString* aThis, uint32_t aLength)
|
2017-01-14 09:02:14 +03:00
|
|
|
{
|
2017-03-20 21:40:25 +03:00
|
|
|
aThis->SetLength(aLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Gecko_FallibleAssignCString(nsACString* aThis, const nsACString* aOther)
|
|
|
|
{
|
|
|
|
return aThis->Assign(*aOther, mozilla::fallible);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Gecko_FallibleAppendCString(nsACString* aThis, const nsACString* aOther)
|
|
|
|
{
|
|
|
|
return aThis->Append(*aOther, mozilla::fallible);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Gecko_FallibleSetLengthCString(nsACString* aThis, uint32_t aLength)
|
|
|
|
{
|
|
|
|
return aThis->SetLength(aLength, mozilla::fallible);
|
2017-01-14 09:02:14 +03:00
|
|
|
}
|
|
|
|
|
2017-04-25 13:17:48 +03:00
|
|
|
char* Gecko_BeginWritingCString(nsACString* aThis)
|
|
|
|
{
|
|
|
|
return aThis->BeginWriting();
|
|
|
|
}
|
|
|
|
|
|
|
|
char* Gecko_FallibleBeginWritingCString(nsACString* aThis)
|
|
|
|
{
|
|
|
|
return aThis->BeginWriting(mozilla::fallible);
|
|
|
|
}
|
|
|
|
|
2016-08-17 01:05:05 +03:00
|
|
|
void Gecko_FinalizeString(nsAString* aThis)
|
|
|
|
{
|
|
|
|
aThis->~nsAString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Gecko_AssignString(nsAString* aThis, const nsAString* aOther)
|
|
|
|
{
|
|
|
|
aThis->Assign(*aOther);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Gecko_AppendString(nsAString* aThis, const nsAString* aOther)
|
|
|
|
{
|
|
|
|
aThis->Append(*aOther);
|
|
|
|
}
|
|
|
|
|
2017-03-20 21:40:25 +03:00
|
|
|
void Gecko_SetLengthString(nsAString* aThis, uint32_t aLength)
|
|
|
|
{
|
|
|
|
aThis->SetLength(aLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Gecko_FallibleAssignString(nsAString* aThis, const nsAString* aOther)
|
|
|
|
{
|
|
|
|
return aThis->Assign(*aOther, mozilla::fallible);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Gecko_FallibleAppendString(nsAString* aThis, const nsAString* aOther)
|
|
|
|
{
|
|
|
|
return aThis->Append(*aOther, mozilla::fallible);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Gecko_FallibleSetLengthString(nsAString* aThis, uint32_t aLength)
|
2017-01-14 09:02:14 +03:00
|
|
|
{
|
2017-03-20 21:40:25 +03:00
|
|
|
return aThis->SetLength(aLength, mozilla::fallible);
|
2017-01-14 09:02:14 +03:00
|
|
|
}
|
|
|
|
|
2017-04-25 13:17:48 +03:00
|
|
|
char16_t* Gecko_BeginWritingString(nsAString* aThis)
|
|
|
|
{
|
|
|
|
return aThis->BeginWriting();
|
|
|
|
}
|
|
|
|
|
|
|
|
char16_t* Gecko_FallibleBeginWritingString(nsAString* aThis)
|
|
|
|
{
|
|
|
|
return aThis->BeginWriting(mozilla::fallible);
|
|
|
|
}
|
|
|
|
|
2016-08-17 01:05:05 +03:00
|
|
|
} // extern "C"
|