Skip to content

Commit 668660e

Browse files
committed
Optimize whitespace collapsing.
We don't need to find endspace here; while visually it's nice, JavaScript really doesn't care whether it's a "space" or "carriage-return". So, don't bother looking for an endspace, and speed this up a bit.
1 parent 73128e6 commit 668660e

2 files changed

Lines changed: 4 additions & 12 deletions

File tree

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Revision history for Perl extension JavaScript::Minifier::XS.
44
- rewrote test suite into a single ".t" test
55
- optimized memory allocations, by allocating Nodes in bulk, and being
66
smarter about when we need to free/reallocate content buffers in Nodes
7+
- optimize whitespace collapsing
78

89
0.13 2020-12-30 21:46:29-08:00 America/Vancouver
910
- POD cleanups; spelling, SYNOPSIS

XS.xs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -280,20 +280,11 @@ void JsAppendNode(Node* element, Node* node) {
280280
element->next = node;
281281
}
282282

283-
/* collapses a node to a single whitespace character. If the node contains any
284-
* endspace characters, that is what we're collapsed to.
285-
*/
283+
/* collapses a node to a single whitespace character */
286284
void JsCollapseNodeToWhitespace(Node* node) {
287285
if (node->contents) {
288-
char ws = node->contents[0];
289-
size_t idx;
290-
for (idx=0; idx<node->length; idx++) {
291-
if (charIsEndspace(node->contents[idx])) {
292-
ws = node->contents[idx];
293-
break;
294-
}
295-
}
296-
JsSetNodeContents(node, &ws, 1);
286+
node->length = 1;
287+
node->contents[1] = '\0';
297288
}
298289
}
299290

0 commit comments

Comments
 (0)