Skip to content

Commit

Permalink
Merge 9e2264c into db10c42
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasso committed Sep 2, 2018
2 parents db10c42 + 9e2264c commit 86232fe
Show file tree
Hide file tree
Showing 45 changed files with 370 additions and 551 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ WASM_OPTIONS = \
--llvm-opts 3 \
--js-opts 1 \
--closure 1 \
-s ENVIRONMENT=node \
-s MODULARIZE=1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s AGGRESSIVE_VARIABLE_ELIMINATION=1 \
Expand All @@ -79,6 +80,7 @@ ASMJS_OPTIONS = \
--llvm-opts 3 \
--js-opts 1 \
--closure 1 \
-s ENVIRONMENT=node \
-s MODULARIZE=1 \
-s AGGRESSIVE_VARIABLE_ELIMINATION=1 \
-s ELIMINATE_DUPLICATE_FUNCTIONS=1 \
Expand Down
Binary file modified compiled/asm-dom.a
Binary file not shown.
Binary file modified compiled/asm-dom.bc
Binary file not shown.
Binary file modified compiled/asm-dom.o
Binary file not shown.
190 changes: 93 additions & 97 deletions compiled/asmjs/asm-dom.asm.js

Large diffs are not rendered by default.

170 changes: 85 additions & 85 deletions compiled/wasm/asm-dom.js

Large diffs are not rendered by default.

Binary file modified compiled/wasm/asm-dom.wasm
Binary file not shown.
8 changes: 8 additions & 0 deletions cpp/Config/Config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "Config.hpp"

namespace asmdom {

bool CLEAR_MEMORY = true;
bool UNSAFE_PATCH = false;

}
16 changes: 16 additions & 0 deletions cpp/Config/Config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef asmdom_Config_hpp
#define asmdom_Config_hpp

namespace asmdom {

extern bool CLEAR_MEMORY;
extern bool UNSAFE_PATCH;

struct Config {
bool clearMemory = true;
bool unsafePatch = false;
};

}

#endif
7 changes: 3 additions & 4 deletions cpp/Init/init.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#include "init.hpp"
#include "../VDOMConfig/VDOMConfig.hpp"
#include "../Config/Config.hpp"
#include <emscripten.h>

namespace asmdom {

void init(const Config& config) {
VDOMConfig& vdomconfig = VDOMConfig::getConfig();
vdomconfig.setClearMemory(config.clearMemory);
vdomconfig.setUnsafePatch(config.unsafePatch);
CLEAR_MEMORY = config.clearMemory;
UNSAFE_PATCH = config.unsafePatch;

EM_ASM(
#ifndef ASMDOM_JS_SIDE
Expand Down
7 changes: 2 additions & 5 deletions cpp/Init/init.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#ifndef asmdom_Init_hpp
#define asmdom_Init_hpp

namespace asmdom {
#include "../Config/Config.hpp"

struct Config {
bool clearMemory = true;
bool unsafePatch = false;
};
namespace asmdom {

void init(const Config& config);

Expand Down
21 changes: 11 additions & 10 deletions cpp/Patch/patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "../Diff/diff.hpp"
#include "../VNode/VNode.hpp"
#include "../h/h.hpp"
#include "../VDOMConfig/VDOMConfig.hpp"
#include "../Config/Config.hpp"
#include <emscripten/val.h>
#include <algorithm>
#include <cstdint>
Expand All @@ -26,6 +26,8 @@ namespace asmdom {
#ifdef ASMDOM_TEST
void reset() {
currentNode = NULL;
CLEAR_MEMORY = true;
UNSAFE_PATCH = false;
};
#endif

Expand Down Expand Up @@ -146,15 +148,15 @@ namespace asmdom {
} else if (!oldEndVnode) {
oldEndVnode = oldCh[--oldEndIdx];
} else if (sameVNode(oldStartVnode, newStartVnode)) {
patchVNode(oldStartVnode, newStartVnode, parentElm);
if (oldStartVnode != newStartVnode) patchVNode(oldStartVnode, newStartVnode, parentElm);
oldStartVnode = oldCh[++oldStartIdx];
newStartVnode = newCh[++newStartIdx];
} else if (sameVNode(oldEndVnode, newEndVnode)) {
patchVNode(oldEndVnode, newEndVnode, parentElm);
if (oldEndVnode != newEndVnode) patchVNode(oldEndVnode, newEndVnode, parentElm);
oldEndVnode = oldCh[--oldEndIdx];
newEndVnode = newCh[--newEndIdx];
} else if (sameVNode(oldStartVnode, newEndVnode)) {
patchVNode(oldStartVnode, newEndVnode, parentElm);
if (oldStartVnode != newEndVnode) patchVNode(oldStartVnode, newEndVnode, parentElm);

EM_ASM_({
Module.insertBefore(
Expand All @@ -166,7 +168,7 @@ namespace asmdom {
oldStartVnode = oldCh[++oldStartIdx];
newEndVnode = newCh[--newEndIdx];
} else if (sameVNode(oldEndVnode, newStartVnode)) {
patchVNode(oldEndVnode, newStartVnode, parentElm);
if (oldEndVnode != newStartVnode) patchVNode(oldEndVnode, newStartVnode, parentElm);

EM_ASM_({
Module.insertBefore($0, $1, $2);
Expand Down Expand Up @@ -195,7 +197,7 @@ namespace asmdom {
Module.insertBefore($0, $1, $2);
}, parentElm, createElm(newStartVnode), oldStartVnode->elm);
} else {
patchVNode(elmToMove, newStartVnode, parentElm);
if (elmToMove != newStartVnode) patchVNode(elmToMove, newStartVnode, parentElm);
oldCh[oldKeyToIdx[newStartVnode->key]] = NULL;
EM_ASM_({
Module.insertBefore($0, $1, $2);
Expand Down Expand Up @@ -240,17 +242,16 @@ namespace asmdom {
VNode* patch(const emscripten::val& element, VNode* const vnode) {
VNode* oldVnode = toVNode(element);
VNode* result = patch(oldVnode, vnode);
if (!VDOMConfig::getConfig().getClearMemory()) {
if (!CLEAR_MEMORY) {
deleteVNode(oldVnode);
}
return result;
};

VNode* patch(VNode* const oldVnode, VNode* const vnode) {
#ifndef ASMDOM_JS_SIDE
VDOMConfig& config = VDOMConfig::getConfig();
if (
!config.getUnsafePatch() &&
!UNSAFE_PATCH &&
currentNode != oldVnode && currentNode
) return NULL;
#endif
Expand Down Expand Up @@ -278,7 +279,7 @@ namespace asmdom {
}

#ifndef ASMDOM_JS_SIDE
if (config.getClearMemory()) {
if (CLEAR_MEMORY) {
deleteVNode(oldVnode);
}
#endif
Expand Down
21 changes: 0 additions & 21 deletions cpp/VDOMConfig/VDOMConfig.cpp

This file was deleted.

28 changes: 0 additions & 28 deletions cpp/VDOMConfig/VDOMConfig.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion cpp/asm-dom.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "VDOMConfig/VDOMConfig.cpp"
#include "Config/Config.cpp"
#include "VNode/VNode.cpp"
#include "h/h.cpp"
#include "toVNode/toVNode.cpp"
Expand Down
2 changes: 1 addition & 1 deletion cpp/asm-dom.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cpp/domApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ var addPtr = function addPtr(node) {
if (node === null) return 0;
if (node.asmDomPtr !== undefined) return node.asmDomPtr;
nodes[++lastPtr] = node;
node.asmDomPtr = lastPtr;
return lastPtr;
// eslint-disable-next-line
return node.asmDomPtr = lastPtr;
};

exports['default'] = {
Expand Down
12 changes: 2 additions & 10 deletions cpp/domRecycler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,12 @@ var recycler = {
create: function create(name) {
name = name.toUpperCase();
var list = recycler.nodes[name];
if (list !== undefined) {
var node = list.pop();
if (node !== undefined) return node;
}
return document.createElement(name);
return list !== undefined && list.pop() || document.createElement(name);
},
createNS: function createNS(name, ns) {
name = name.toUpperCase();
var list = recycler.nodes[name + ns];
if (list !== undefined) {
var _node = list.pop();
if (_node !== undefined) return _node;
}
var node = document.createElementNS(ns, name);
var node = list !== undefined && list.pop() || document.createElementNS(ns, name);
node.asmDomNS = ns;
return node;
},
Expand Down
6 changes: 3 additions & 3 deletions cpp/toHTML/toHTML.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "toHTML.hpp"
#include "../utils/utils.hpp"
#include "../VNode/VNode.hpp"
#include "../VDOMConfig/VDOMConfig.hpp"
#include "../Config/Config.hpp"
#include <emscripten/val.h>
#include <unordered_map>
#include <string>
Expand Down Expand Up @@ -171,8 +171,8 @@ namespace asmdom {
toHTML(vnode, html);

#ifndef ASMDOM_JS_SIDE
if (vnode && VDOMConfig::getConfig().getClearMemory()) {
deleteVNode(vnode);
if (vnode && CLEAR_MEMORY) {
deleteVNode(vnode);
}
#endif

Expand Down
Loading

0 comments on commit 86232fe

Please sign in to comment.