mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 1344629 - Part 4: Cleanup: make string tuples not think in terms of "substring". r=dbaron
In the next patch, tuples will work on nsTStringRepr rather than nsTSubstring, so the notions of TO_SUBSTRING and substring_type are not quite right. MozReview-Commit-ID: LpUwmGQAWVO --HG-- extra : rebase_source : 6142500a3d4218d74dda11736b94cf08d6f55335
This commit is contained in:
parent
6ebaf62ee9
commit
02daf1d0c9
@ -6,9 +6,6 @@
|
||||
|
||||
#include "nsSubstringTuple.h"
|
||||
|
||||
// convert fragment to |const substring_type&|
|
||||
#define TO_SUBSTRING(_v) (*(_v))
|
||||
|
||||
// define nsSubstringTuple
|
||||
#include "string-template-def-unichar.h"
|
||||
#include "nsTSubstringTuple.cpp"
|
||||
|
@ -17,10 +17,10 @@ nsTSubstringTuple_CharT::Length() const
|
||||
if (mHead) {
|
||||
len = mHead->Length();
|
||||
} else {
|
||||
len = TO_SUBSTRING(mFragA).Length();
|
||||
len = mFragA->Length();
|
||||
}
|
||||
|
||||
len += TO_SUBSTRING(mFragB).Length();
|
||||
len += mFragB->Length();
|
||||
MOZ_RELEASE_ASSERT(len.isValid(), "Substring tuple length is invalid");
|
||||
return len.value();
|
||||
}
|
||||
@ -35,41 +35,16 @@ nsTSubstringTuple_CharT::Length() const
|
||||
void
|
||||
nsTSubstringTuple_CharT::WriteTo(char_type* aBuf, uint32_t aBufLen) const
|
||||
{
|
||||
const substring_type& b = TO_SUBSTRING(mFragB);
|
||||
|
||||
MOZ_RELEASE_ASSERT(aBufLen >= b.Length(), "buffer too small");
|
||||
uint32_t headLen = aBufLen - b.Length();
|
||||
MOZ_RELEASE_ASSERT(aBufLen >= mFragB->Length(), "buffer too small");
|
||||
uint32_t headLen = aBufLen - mFragB->Length();
|
||||
if (mHead) {
|
||||
mHead->WriteTo(aBuf, headLen);
|
||||
} else {
|
||||
const substring_type& a = TO_SUBSTRING(mFragA);
|
||||
|
||||
MOZ_RELEASE_ASSERT(a.Length() == headLen, "buffer incorrectly sized");
|
||||
char_traits::copy(aBuf, a.Data(), a.Length());
|
||||
MOZ_RELEASE_ASSERT(mFragA->Length() == headLen, "buffer incorrectly sized");
|
||||
char_traits::copy(aBuf, mFragA->Data(), mFragA->Length());
|
||||
}
|
||||
|
||||
char_traits::copy(aBuf + headLen, b.Data(), b.Length());
|
||||
|
||||
#if 0
|
||||
// we need to write out data into |aBuf|, ending at |aBuf + aBufLen|. So our
|
||||
// data needs to precede |aBuf + aBufLen| exactly. We trust that the buffer
|
||||
// was properly sized!
|
||||
|
||||
const substring_type& b = TO_SUBSTRING(mFragB);
|
||||
|
||||
NS_ASSERTION(aBufLen >= b.Length(), "buffer is too small");
|
||||
char_traits::copy(aBuf + aBufLen - b.Length(), b.Data(), b.Length());
|
||||
|
||||
aBufLen -= b.Length();
|
||||
|
||||
if (mHead) {
|
||||
mHead->WriteTo(aBuf, aBufLen);
|
||||
} else {
|
||||
const substring_type& a = TO_SUBSTRING(mFragA);
|
||||
NS_ASSERTION(aBufLen == a.Length(), "buffer is too small");
|
||||
char_traits::copy(aBuf, a.Data(), a.Length());
|
||||
}
|
||||
#endif
|
||||
char_traits::copy(aBuf + headLen, mFragB->Data(), mFragB->Length());
|
||||
}
|
||||
|
||||
|
||||
@ -84,7 +59,7 @@ nsTSubstringTuple_CharT::IsDependentOn(const char_type* aStart,
|
||||
{
|
||||
// we aStart with the right-most fragment since it is faster to check.
|
||||
|
||||
if (TO_SUBSTRING(mFragB).IsDependentOn(aStart, aEnd)) {
|
||||
if (mFragB->IsDependentOn(aStart, aEnd)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -92,5 +67,5 @@ nsTSubstringTuple_CharT::IsDependentOn(const char_type* aStart,
|
||||
return mHead->IsDependentOn(aStart, aEnd);
|
||||
}
|
||||
|
||||
return TO_SUBSTRING(mFragA).IsDependentOn(aStart, aEnd);
|
||||
return mFragA->IsDependentOn(aStart, aEnd);
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ public:
|
||||
typedef nsCharTraits<char_type> char_traits;
|
||||
|
||||
typedef nsTSubstringTuple_CharT self_type;
|
||||
typedef nsTSubstring_CharT substring_type;
|
||||
typedef nsTSubstring_CharT base_string_type;
|
||||
typedef uint32_t size_type;
|
||||
|
||||
@ -64,9 +63,9 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
const self_type* mHead;
|
||||
const base_string_type* mFragA;
|
||||
const base_string_type* mFragB;
|
||||
const self_type* const mHead;
|
||||
const base_string_type* const mFragA;
|
||||
const base_string_type* const mFragB;
|
||||
};
|
||||
|
||||
inline const nsTSubstringTuple_CharT
|
||||
|
Loading…
Reference in New Issue
Block a user