Skip to content

Commit

Permalink
make it more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
iacore committed Jun 9, 2024
1 parent d3fda1d commit 439d0fe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
16 changes: 9 additions & 7 deletions cjs/interface/document-fragment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const {DOCUMENT_FRAGMENT_NODE} = require('../shared/constants.js');
const {DOCUMENT_FRAGMENT_NODE, TEXT_NODE} = require('../shared/constants.js');
const {NonElementParentNode} = require('../mixin/non-element-parent-node.js');
const {NEXT, END} = require('../shared/symbols.js')

/**
* @implements globalThis.DocumentFragment
Expand All @@ -11,13 +12,14 @@ class DocumentFragment extends NonElementParentNode {
}

get textContent() {
let r = ""
let curr = this.firstChild
while (curr) {
r += curr.textContent
curr = curr.nextSibling
const text = [];
let {[NEXT]: next, [END]: end} = this;
while (next !== end) {
if (next.nodeType === TEXT_NODE)
text.push(next.textContent);
next = next[NEXT];
}
return r;
return text.join('');
}
}
exports.DocumentFragment = DocumentFragment
16 changes: 9 additions & 7 deletions esm/interface/document-fragment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {DOCUMENT_FRAGMENT_NODE} from '../shared/constants.js';
import {DOCUMENT_FRAGMENT_NODE, TEXT_NODE} from '../shared/constants.js';
import {NonElementParentNode} from '../mixin/non-element-parent-node.js';
import {NEXT, END} from '../shared/symbols.js'

/**
* @implements globalThis.DocumentFragment
Expand All @@ -10,12 +11,13 @@ export class DocumentFragment extends NonElementParentNode {
}

get textContent() {
let r = ""
let curr = this.firstChild
while (curr) {
r += curr.textContent
curr = curr.nextSibling
const text = [];
let {[NEXT]: next, [END]: end} = this;
while (next !== end) {
if (next.nodeType === TEXT_NODE)
text.push(next.textContent);
next = next[NEXT];
}
return r;
return text.join('');
}
}
13 changes: 7 additions & 6 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7170,13 +7170,14 @@ let DocumentFragment$1 = class DocumentFragment extends NonElementParentNode {
}

get textContent() {
let r = "";
let curr = this.firstChild;
while (curr) {
r += curr.textContent;
curr = curr.nextSibling;
const text = [];
let {[NEXT]: next, [END]: end} = this;
while (next !== end) {
if (next.nodeType === TEXT_NODE)
text.push(next.textContent);
next = next[NEXT];
}
return r;
return text.join('');
}
};

Expand Down

0 comments on commit 439d0fe

Please sign in to comment.