Closed Bug 230633 Opened 21 years ago Closed 21 years ago

Constify Transformiix code a bit

Categories

(Core :: XSLT, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: peterv, Assigned: peterv)

Details

Attachments

(4 files, 1 obsolete file)

I've contified some data in Transformiix, I've also moved to the new XPCOM
static atoms. Here's what size shows:

Trunk
Segment __TEXT: 679936
Segment __DATA: 69632
Segment __LINKEDIT: 487424
total 1236992

With constify patch
Segment __TEXT: 679936
Segment __DATA: 61440
Segment __LINKEDIT: 487424
total 1228800

With atoms patch
Segment __TEXT: 663552
Segment __DATA: 65536
Segment __LINKEDIT: 491520
total 1220608
Attached patch Constify patch v1 (obsolete) — Splinter Review
Attachment #138807 - Flags: review?(bugmail)
Attachment #138808 - Flags: review?(axel)
Actually, nevermind the constify patch v1. It doesn't work, I'll attach a new
one. Here's the numbers with atoms and the new constify patch:

Segment __TEXT: 659456
Segment __DATA: 65536
Segment __LINKEDIT: 491520
total 1216512
Attachment #138807 - Attachment is obsolete: true
Attachment #138807 - Flags: review?(bugmail)
Attachment #138816 - Flags: review?(bugmail)
Comment on attachment 138808 [details] [diff] [review]
Static atoms patch v1

AFAICT,
+static const nsStaticAtom XMLAtoms_info[] = {
+#define TX_ATOM(name_, value_) { value_, &txXMLAtoms::name_ },
+XML_ATOMS
+#undef TX_ATOM
+};
leaves us with a 
{
{foo, &txXSLTAtoms::foo},
{bar, &txXSLTAtoms::bar},
}

Note the trailing , in the last entry, does that compile cross platform? IIRC
it does not for enums or so.
I copied that from the layout atoms (see for example nsHTMLAtoms:
http://lxr.mozilla.org/seamonkey/source/content/shared/src/nsHTMLAtoms.cpp#47),
and it certainly seems to be compiling there :-).
Comment on attachment 138808 [details] [diff] [review]
Static atoms patch v1

>Index: source/base/txStringUtils.cpp

>+PRBool
>+TX_StringEqualsAtom(const nsASingleFragmentString& aString, nsIAtom* aAtom)
>+{
>+    const char* atom;
>+    aAtom->GetUTF8String(&atom);
>+
>+    PRUint32 ASCIILength = strlen(atom);
>+    nsDependentCString ASCIIString(atom, ASCIILength);

This string ain't needed, drop ASCIIIter and just use atom.
Or rename it atomchar or so.

>+
>+    PRUint32 UTF16Length = aString.Length();
>+    if (ASCIILength != UTF16Length) {
>+        return PR_FALSE;
>+    }
>+
>+    const char* ASCIIIter;
>+    ASCIIString.BeginReading(ASCIIIter);
>+
>+    const PRUnichar* UTF16Iter;
>+    aString.BeginReading(UTF16Iter);
>+
>+    while (ASCIIIter) {
>+        if (PRUnichar(*ASCIIIter) != *UTF16Iter) {
>+            return PR_FALSE;
>+        }
>+        ++ASCIIIter;
>+        ++UTF16Iter;
>+    }
>+
>+    return PR_TRUE;
>+}
>+
Attachment #138808 - Flags: review?(axel) → review+
Comment on attachment 138816 [details] [diff] [review]
Constify patch v1.1

>@@ -374,7 +374,8 @@ txStylesheetCompiler::endElement()
>         }
>     }
> 
>-    txElementHandler* handler = NS_STATIC_CAST(txElementHandler*, popPtr());
>+    const txElementHandler* handler =
>+        NS_STATIC_CAST(const txElementHandler*, popPtr());
>     rv = (handler->mEndFunction)(*this);
>     NS_ENSURE_SUCCESS(rv, rv);

I'm a little worried that this won't compile cross-platform ( casting from
non-const to const using explicit static-cast). But if it works then this
definitly looks better then any alternatives.

>+#define INIT_HANDLER_WITH_ELEMENT_HANDLER(_name)                     \
>+    INIT_HANDLER(_name);                                             \
>+                                                                     \
>+    rv = gTx##_name##Handler->init(&gTx##_name##ElementHandler, 1);  \
>+    if (NS_FAILED(rv))                                               \
>+        return PR_FALSE
>+
>+#define INIT_HANDLER_WITH_ELEMENT_HANDLERS(_name)                    \
>+    INIT_HANDLER(_name);                                             \
>+                                                                     \
>+    rv = gTx##_name##Handler->init(gTx##_name##ElementHandlers,      \
>+                                   NS_ARRAY_LENGTH(gTx##_name##ElementHandlers)); \
>+    if (NS_FAILED(rv))                                               \
>+        return PR_FALSE

It think it'd fine to not differentiate between handlers that have 1 and
handlers that have 2+ element-handlers. Just creating a list with one element
shouldn't change the code.

r=me either way
Attachment #138816 - Flags: review?(bugmail) → review+
Attachment #138808 - Flags: superreview?(jst)
Attachment #138816 - Flags: superreview?
Comment on attachment 138808 [details] [diff] [review]
Static atoms patch v1

TX_StringEqualsAtom():

+    nsDependentCString ASCIIString(atom, ASCIILength);

Like Pike said, loose ASCIIString.

sr=jst
Attachment #138808 - Flags: superreview?(jst) → superreview+
Comment on attachment 138816 [details] [diff] [review]
Constify patch v1.1

Doh.
Attachment #138816 - Flags: superreview? → superreview?(jst)
Comment on attachment 138816 [details] [diff] [review]
Constify patch v1.1

sr=jst
Attachment #138816 - Flags: superreview?(jst) → superreview+
Visual C++ seems to have a bug that causes it to break on

struct whatever {
    const int i;
};

const whatever temp = { 0 };

which is valid afaik, so i had to remove a bunch of const's from the patch.
Fortunately it didn't seem to have an influence on the decrease in the Z
numbers. Decrease in codesighs was about -11k on Windows, -17k on Linux and -22k
on OS X.
Fixed.
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Someone left a pile of poo in the living room. And I reviewed it. Darn.

TX_StringEqualsAtom regressed, patch coming up.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Comment on attachment 139413 [details] [diff] [review]
check the char instead of the char* for null termination

requesting r/sr from peterv for one-line-bustage-fix
Attachment #139413 - Flags: superreview?(peterv)
Attachment #139413 - Flags: review?(peterv)
Comment on attachment 139413 [details] [diff] [review]
check the char instead of the char* for null termination

sure
Attachment #139413 - Flags: superreview+
Attachment #139413 - Flags: review+
Attachment #139413 - Flags: superreview?(peterv)
Attachment #139413 - Flags: review?(peterv)
attachement 139413 checked in
Status: REOPENED → RESOLVED
Closed: 21 years ago21 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: