nsTextFragment& nsTextFragment::operator=(const nsTextFragment& aOther) { ReleaseText(); if (aOther.mState.mLength) { if (!aOther.mState.mInHeap) { m1b = aOther.m1b; // This will work even if aOther is using m2b } else { size_t m2bSize = aOther.mState.mLength * (aOther.mState.mIs2b ? sizeof(char16_t) : sizeof(char)); m2b = static_cast<char16_t*>(malloc(m2bSize)); if (m2b) { memcpy(m2b, aOther.m2b, m2bSize); } else { // allocate a buffer for a single REPLACEMENT CHARACTER m2b = static_cast<char16_t*>(moz_xmalloc(sizeof(char16_t))); m2b[0] = 0xFFFD; // REPLACEMENT CHARACTER mState.mIs2b = true; mState.mInHeap = true; mState.mLength = 1; } } if (m1b) { mAllBits = aOther.mAllBits; } } return *this; }
//================================== // 函数:D3DRelease() // 目的:释放Direct3D及Direct3D设备对象 // VOID _ReleaseD3D() { //卸载系统鼠标指针 if(system_cur) delete system_cur; ReleaseText(); ReleaseImg(); if( g_pd3dD != NULL ) g_pd3dD->Release(); if( g_pD3D != NULL ) g_pD3D->Release(); }
nsTextFragment& nsTextFragment::operator=(const nsTextFragment& aOther) { ReleaseText(); if (aOther.mState.mLength) { if (!aOther.mState.mInHeap) { m1b = aOther.m1b; // This will work even if aOther is using m2b } else { m2b = static_cast<PRUnichar*> (nsMemory::Clone(aOther.m2b, aOther.mState.mLength * (aOther.mState.mIs2b ? sizeof(PRUnichar) : sizeof(char)))); } if (m1b) { mAllBits = aOther.mAllBits; } } return *this; }
void nsTextFragment::SetTo(const PRUnichar* aBuffer, PRInt32 aLength, PRBool aUpdateBidi) { ReleaseText(); if (aLength == 0) { return; } PRUnichar firstChar = *aBuffer; if (aLength == 1 && firstChar < 256) { m1b = sSingleCharSharedString + firstChar; mState.mInHeap = PR_FALSE; mState.mIs2b = PR_FALSE; mState.mLength = 1; return; } const PRUnichar *ucp = aBuffer; const PRUnichar *uend = aBuffer + aLength; // Check if we can use a shared string if (aLength <= 1 + TEXTFRAG_WHITE_AFTER_NEWLINE + TEXTFRAG_MAX_NEWLINES && (firstChar == ' ' || firstChar == '\n' || firstChar == '\t')) { if (firstChar == ' ') { ++ucp; } const PRUnichar* start = ucp; while (ucp < uend && *ucp == '\n') { ++ucp; } const PRUnichar* endNewLine = ucp; PRUnichar space = ucp < uend && *ucp == '\t' ? '\t' : ' '; while (ucp < uend && *ucp == space) { ++ucp; } if (ucp == uend && endNewLine - start <= TEXTFRAG_MAX_NEWLINES && ucp - endNewLine <= TEXTFRAG_WHITE_AFTER_NEWLINE) { char** strings = space == ' ' ? sSpaceSharedString : sTabSharedString; m1b = strings[endNewLine - start]; // If we didn't find a space in the beginning, skip it now. if (firstChar != ' ') { ++m1b; } mState.mInHeap = PR_FALSE; mState.mIs2b = PR_FALSE; mState.mLength = aLength; return; } } // See if we need to store the data in ucs2 or not PRInt32 first16bit = FirstNon8Bit(ucp, uend); if (first16bit != -1) { // aBuffer contains no non-8bit character // Use ucs2 storage because we have to m2b = (PRUnichar *)nsMemory::Clone(aBuffer, aLength * sizeof(PRUnichar)); if (!m2b) { return; } mState.mIs2b = PR_TRUE; if (aUpdateBidi) { UpdateBidiFlag(aBuffer + first16bit, aLength - first16bit); } } else { // Use 1 byte storage because we can char* buff = (char *)nsMemory::Alloc(aLength * sizeof(char)); if (!buff) { return; } // Copy data LossyConvertEncoding16to8 converter(buff); copy_string(aBuffer, aBuffer+aLength, converter); m1b = buff; mState.mIs2b = PR_FALSE; } // Setup our fields mState.mInHeap = PR_TRUE; mState.mLength = aLength; }
nsTextFragment::~nsTextFragment() { ReleaseText(); MOZ_COUNT_DTOR(nsTextFragment); }
void nsTextFragment::SetTo(const PRUnichar* aBuffer, PRInt32 aLength) { ReleaseText(); if (aLength == 0) { return; } PRUnichar firstChar = *aBuffer; if (aLength == 1 && firstChar < 256) { m1b = sSingleCharSharedString + firstChar; mState.mInHeap = PR_FALSE; mState.mIs2b = PR_FALSE; mState.mLength = 1; return; } const PRUnichar *ucp = aBuffer; const PRUnichar *uend = aBuffer + aLength; // Check if we can use a shared string if (firstChar == ' ' || firstChar == '\n' || firstChar == '\t') { if (firstChar == ' ') { ++ucp; } const PRUnichar* start = ucp; while (ucp < uend && *ucp == '\n') { ++ucp; } const PRUnichar* endNewLine = ucp; PRUnichar space = ucp < uend && *ucp == '\t' ? '\t' : ' '; while (ucp < uend && *ucp == space) { ++ucp; } if (ucp == uend && endNewLine - start <= TEXTFRAG_MAX_NEWLINES && ucp - endNewLine <= TEXTFRAG_WHITE_AFTER_NEWLINE) { char** strings = space == ' ' ? sSpaceSharedString : sTabSharedString; m1b = strings[endNewLine - start]; // If we didn't find a space in the beginning, skip it now. if (firstChar != ' ') { ++m1b; } mState.mInHeap = PR_FALSE; mState.mIs2b = PR_FALSE; mState.mLength = aLength; return; } } // See if we need to store the data in ucs2 or not PRBool need2 = PR_FALSE; while (ucp < uend) { PRUnichar ch = *ucp++; if (ch >= 256) { need2 = PR_TRUE; break; } } if (need2) { // Use ucs2 storage because we have to m2b = (PRUnichar *)nsMemory::Clone(aBuffer, aLength * sizeof(PRUnichar)); if (!m2b) { return; } } else { // Use 1 byte storage because we can char* buff = (char *)nsMemory::Alloc(aLength * sizeof(char)); if (!buff) { return; } // Copy data for (PRUint32 i = 0; i < (PRUint32)aLength; ++i) { buff[i] = (char)aBuffer[i]; } m1b = buff; } // Setup our fields mState.mInHeap = PR_TRUE; mState.mIs2b = need2; mState.mLength = aLength; }
nsTextFragment::~nsTextFragment() { ReleaseText(); }
void nsTextFragment::SetTo(const PRUnichar* aBuffer, PRInt32 aLength) { ReleaseText(); if (aLength == 0) { return; } PRUnichar firstChar = *aBuffer; if (aLength == 1 && firstChar < 256) { m1b = sSingleCharSharedString + firstChar; mState.mInHeap = PR_FALSE; mState.mIs2b = PR_FALSE; mState.mLength = 1; return; } const PRUnichar *ucp = aBuffer; const PRUnichar *uend = aBuffer + aLength; // Check if we can use a shared string if (firstChar == ' ' || firstChar == '\n' || firstChar == '\t') { if (firstChar == ' ') { ++ucp; } const PRUnichar* start = ucp; while (ucp < uend && *ucp == '\n') { ++ucp; } const PRUnichar* endNewLine = ucp; PRUnichar space = ucp < uend && *ucp == '\t' ? '\t' : ' '; while (ucp < uend && *ucp == space) { ++ucp; } if (ucp == uend && endNewLine - start <= TEXTFRAG_MAX_NEWLINES && ucp - endNewLine <= TEXTFRAG_WHITE_AFTER_NEWLINE) { char** strings = space == ' ' ? sSpaceSharedString : sTabSharedString; m1b = strings[endNewLine - start]; // If we didn't find a space in the beginning, skip it now. if (firstChar != ' ') { ++m1b; } mState.mInHeap = PR_FALSE; mState.mIs2b = PR_FALSE; mState.mLength = aLength; return; } } // We don't attempt to detect if large text nodes can be stored compactly, // because that wastes too much time. const PRInt32 LARGE_STRING_THRESHOLD = 10240; // 10KB PRBool need2 = aLength >= LARGE_STRING_THRESHOLD; if (!need2) { // See if we need to store the data in ucs2 or not while (ucp < uend) { PRUnichar ch = *ucp++; if (ch >= 256) { need2 = PR_TRUE; break; } } } if (need2) { // Use ucs2 storage because we have to m2b = (PRUnichar *)nsMemory::Clone(aBuffer, aLength * sizeof(PRUnichar)); if (!m2b) { return; } } else { // Use 1 byte storage because we can char* buff = (char *)nsMemory::Alloc(aLength * sizeof(char)); if (!buff) { return; } // Copy data // Use the same copying code we use elsewhere; it's likely to be // carefully tuned. LossyConvertEncoding<PRUnichar, char> converter(buff); copy_string(aBuffer, aBuffer+aLength, converter); m1b = buff; } // Setup our fields mState.mInHeap = PR_TRUE; mState.mIs2b = need2; mState.mLength = aLength; }