Bug 500617 - Remove always-zero offsets from HTML5 parser. r=hsivonen

MozReview-Commit-ID: DT8oWxbbYNy
This commit is contained in:
Alphan Chen 2017-10-23 14:42:21 +03:00 коммит произвёл Henri Sivonen
Родитель 2949b2d1b2
Коммит 8e5cbb6713
9 изменённых файлов: 32 добавлений и 41 удалений

Просмотреть файл

@ -291,9 +291,8 @@ public final class AttributeName
* whether to check ncnameness
* @return an <code>AttributeName</code> corresponding to the argument data
*/
@Inline static AttributeName nameByBuffer(@NoLength char[] buf, int offset,
int length
, Interner interner) {
@Inline static AttributeName nameByBuffer(@NoLength char[] buf,
int length, Interner interner) {
// XXX deal with offset
@Unsigned int hash = AttributeName.bufToHash(buf, length);
int[] hashes;
@ -304,7 +303,7 @@ public final class AttributeName
}
AttributeName attributeName = AttributeName.ATTRIBUTE_NAMES[index];
@Local String name = attributeName.getLocal(0);
if (!Portability.localEqualsBuffer(name, buf, offset, length)) {
if (!Portability.localEqualsBuffer(name, buf, length)) {
return null;
}
return attributeName;

Просмотреть файл

@ -158,7 +158,7 @@ public final class ElementName
}
@Inline static ElementName elementNameByBuffer(@NoLength char[] buf,
int offset, int length, Interner interner) {
int length, Interner interner) {
@Unsigned int hash = ElementName.bufToHash(buf, length);
int[] hashes;
hashes = ElementName.ELEMENT_HASHES;
@ -168,7 +168,7 @@ public final class ElementName
} else {
ElementName elementName = ElementName.ELEMENT_NAMES[index];
@Local String name = elementName.name;
if (!Portability.localEqualsBuffer(name, buf, offset, length)) {
if (!Portability.localEqualsBuffer(name, buf, length)) {
return null;
}
return elementName;

Просмотреть файл

@ -35,8 +35,8 @@ public final class Portability {
* Allocates a new local name object. In C++, the refcount must be set up in such a way that
* calling <code>releaseLocal</code> on the return value balances the refcount set by this method.
*/
public static @Local String newLocalNameFromBuffer(@NoLength char[] buf, int offset, int length, Interner interner) {
return new String(buf, offset, length).intern();
public static @Local String newLocalNameFromBuffer(@NoLength char[] buf, int length, Interner interner) {
return new String(buf, 0, length).intern();
}
public static String newStringFromBuffer(@NoLength char[] buf, int offset, int length
@ -78,12 +78,12 @@ public final class Portability {
// Comparison methods
public static boolean localEqualsBuffer(@Local String local, @NoLength char[] buf, int offset, int length) {
public static boolean localEqualsBuffer(@Local String local, @NoLength char[] buf, int length) {
if (local.length() != length) {
return false;
}
for (int i = 0; i < length; i++) {
if (local.charAt(i) != buf[offset + i]) {
if (local.charAt(i) != buf[i]) {
return false;
}
}

Просмотреть файл

@ -712,7 +712,7 @@ public class Tokenizer implements Locator {
return;
}
@Auto char[] asArray = Portability.newCharArrayFromLocal(endTagExpectation);
this.endTagExpectation = ElementName.elementNameByBuffer(asArray, 0,
this.endTagExpectation = ElementName.elementNameByBuffer(asArray,
asArray.length, interner);
assert this.endTagExpectation != null;
endTagExpectationToArray();
@ -910,8 +910,7 @@ public class Tokenizer implements Locator {
* @return the buffer as local name
*/
private void strBufToDoctypeName() {
doctypeName = Portability.newLocalNameFromBuffer(strBuf, 0, strBufLen,
interner);
doctypeName = Portability.newLocalNameFromBuffer(strBuf, strBufLen, interner);
clearStrBufAfterUse();
}
@ -1116,20 +1115,19 @@ public class Tokenizer implements Locator {
if (containsHyphen) {
// We've got a custom element or annotation-xml.
@Local String annotationName = ElementName.ANNOTATION_XML.getName();
if (Portability.localEqualsBuffer(annotationName, strBuf, 0, strBufLen)) {
if (Portability.localEqualsBuffer(annotationName, strBuf, strBufLen)) {
tagName = ElementName.ANNOTATION_XML;
} else {
nonInternedTagName.setNameForNonInterned(Portability.newLocalNameFromBuffer(strBuf, 0, strBufLen,
nonInternedTagName.setNameForNonInterned(Portability.newLocalNameFromBuffer(strBuf, strBufLen,
interner)
// CPPONLY: , true
);
tagName = nonInternedTagName;
}
} else {
tagName = ElementName.elementNameByBuffer(strBuf, 0, strBufLen,
interner);
tagName = ElementName.elementNameByBuffer(strBuf, strBufLen, interner);
if (tagName == null) {
nonInternedTagName.setNameForNonInterned(Portability.newLocalNameFromBuffer(strBuf, 0, strBufLen,
nonInternedTagName.setNameForNonInterned(Portability.newLocalNameFromBuffer(strBuf, strBufLen,
interner)
// CPPONLY: , false
);
@ -1183,11 +1181,11 @@ public class Tokenizer implements Locator {
}
private void attributeNameComplete() throws SAXException {
attributeName = AttributeName.nameByBuffer(strBuf, 0, strBufLen, interner);
attributeName = AttributeName.nameByBuffer(strBuf, strBufLen, interner);
if (attributeName == null) {
// [NOCPP[
attributeName = AttributeName.createAttributeName(
Portability.newLocalNameFromBuffer(strBuf, 0, strBufLen,
Portability.newLocalNameFromBuffer(strBuf, strBufLen,
interner),
namePolicy != XmlViolationPolicy.ALLOW);
// ]NOCPP]

Просмотреть файл

@ -93,7 +93,6 @@ class nsHtml5AttributeName
}
inline static nsHtml5AttributeName* nameByBuffer(char16_t* buf,
int32_t offset,
int32_t length,
nsHtml5AtomTable* interner)
{
@ -107,7 +106,7 @@ class nsHtml5AttributeName
nsHtml5AttributeName* attributeName =
nsHtml5AttributeName::ATTRIBUTE_NAMES[index];
nsAtom* name = attributeName->getLocal(0);
if (!nsHtml5Portability::localEqualsBuffer(name, buf, offset, length)) {
if (!nsHtml5Portability::localEqualsBuffer(name, buf, length)) {
return nullptr;
}
return attributeName;

Просмотреть файл

@ -127,7 +127,6 @@ public:
inline static nsHtml5ElementName* elementNameByBuffer(
char16_t* buf,
int32_t offset,
int32_t length,
nsHtml5AtomTable* interner)
{
@ -141,7 +140,7 @@ public:
nsHtml5ElementName* elementName =
nsHtml5ElementName::ELEMENT_NAMES[index];
nsAtom* name = elementName->name;
if (!nsHtml5Portability::localEqualsBuffer(name, buf, offset, length)) {
if (!nsHtml5Portability::localEqualsBuffer(name, buf, length)) {
return nullptr;
}
return elementName;

Просмотреть файл

@ -9,9 +9,8 @@
#include "nsHtml5TreeBuilder.h"
nsAtom*
nsHtml5Portability::newLocalNameFromBuffer(char16_t* buf, int32_t offset, int32_t length, nsHtml5AtomTable* interner)
nsHtml5Portability::newLocalNameFromBuffer(char16_t* buf, int32_t length, nsHtml5AtomTable* interner)
{
NS_ASSERTION(!offset, "The offset should always be zero here.");
NS_ASSERTION(interner, "Didn't get an atom service.");
return interner->GetAtom(nsDependentSubstring(buf, buf + length));
}
@ -97,9 +96,9 @@ nsHtml5Portability::newLocalFromLocal(nsAtom* local, nsHtml5AtomTable* interner)
}
bool
nsHtml5Portability::localEqualsBuffer(nsAtom* local, char16_t* buf, int32_t offset, int32_t length)
nsHtml5Portability::localEqualsBuffer(nsAtom* local, char16_t* buf, int32_t length)
{
return local->Equals(buf + offset, length);
return local->Equals(buf, length);
}
bool

Просмотреть файл

@ -57,7 +57,7 @@ class nsHtml5StateSnapshot;
class nsHtml5Portability
{
public:
static nsAtom* newLocalNameFromBuffer(char16_t* buf, int32_t offset, int32_t length, nsHtml5AtomTable* interner);
static nsAtom* newLocalNameFromBuffer(char16_t* buf, int32_t length, nsHtml5AtomTable* interner);
static nsHtml5String newStringFromBuffer(char16_t* buf,
int32_t offset,
int32_t length,
@ -70,7 +70,7 @@ class nsHtml5Portability
static jArray<char16_t, int32_t> newCharArrayFromString(
nsHtml5String string);
static nsAtom* newLocalFromLocal(nsAtom* local, nsHtml5AtomTable* interner);
static bool localEqualsBuffer(nsAtom* local, char16_t* buf, int32_t offset, int32_t length);
static bool localEqualsBuffer(nsAtom* local, char16_t* buf, int32_t length);
static bool lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString(
const char* lowerCaseLiteral,
nsHtml5String string);

Просмотреть файл

@ -138,7 +138,7 @@ nsHtml5Tokenizer::setStateAndEndTagExpectation(int32_t specialTokenizerState, ns
return;
}
autoJArray<char16_t,int32_t> asArray = nsHtml5Portability::newCharArrayFromLocal(endTagExpectation);
this->endTagExpectation = nsHtml5ElementName::elementNameByBuffer(asArray, 0, asArray.length, interner);
this->endTagExpectation = nsHtml5ElementName::elementNameByBuffer(asArray, asArray.length, interner);
MOZ_ASSERT(!!this->endTagExpectation);
endTagExpectationToArray();
}
@ -245,7 +245,7 @@ nsHtml5Tokenizer::strBufToString()
void
nsHtml5Tokenizer::strBufToDoctypeName()
{
doctypeName = nsHtml5Portability::newLocalNameFromBuffer(strBuf, 0, strBufLen, interner);
doctypeName = nsHtml5Portability::newLocalNameFromBuffer(strBuf, strBufLen, interner);
clearStrBufAfterUse();
}
@ -295,23 +295,21 @@ nsHtml5Tokenizer::strBufToElementNameString()
if (containsHyphen) {
nsAtom* annotationName = nsHtml5ElementName::ELT_ANNOTATION_XML->getName();
if (nsHtml5Portability::localEqualsBuffer(
annotationName, strBuf, 0, strBufLen)) {
annotationName, strBuf, strBufLen)) {
tagName = nsHtml5ElementName::ELT_ANNOTATION_XML;
} else {
nonInternedTagName->setNameForNonInterned(
nsHtml5Portability::newLocalNameFromBuffer(
strBuf, 0, strBufLen, interner),
true);
strBuf, strBufLen, interner), true);
tagName = nonInternedTagName;
}
} else {
tagName =
nsHtml5ElementName::elementNameByBuffer(strBuf, 0, strBufLen, interner);
nsHtml5ElementName::elementNameByBuffer(strBuf, strBufLen, interner);
if (!tagName) {
nonInternedTagName->setNameForNonInterned(
nsHtml5Portability::newLocalNameFromBuffer(
strBuf, 0, strBufLen, interner),
false);
strBuf, strBufLen, interner), false);
tagName = nonInternedTagName;
}
}
@ -356,11 +354,10 @@ nsHtml5Tokenizer::emitCurrentTagToken(bool selfClosing, int32_t pos)
void
nsHtml5Tokenizer::attributeNameComplete()
{
attributeName = nsHtml5AttributeName::nameByBuffer(strBuf, 0, strBufLen, interner);
attributeName = nsHtml5AttributeName::nameByBuffer(strBuf, strBufLen, interner);
if (!attributeName) {
nonInternedAttributeName->setNameForNonInterned(
nsHtml5Portability::newLocalNameFromBuffer(
strBuf, 0, strBufLen, interner));
nsHtml5Portability::newLocalNameFromBuffer(strBuf, strBufLen, interner));
attributeName = nonInternedAttributeName;
}
clearStrBufAfterUse();