aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-06-24 07:03:33 -0700
committerAlon Zakai <alonzakai@gmail.com>2011-06-24 07:03:33 -0700
commit8859a506cbe16ac95192b782baae49f50cd830f5 (patch)
tree955ac4b8405667465bf8e95be4e356d3127ceef9
parent6a0eae0f483fe49675c81c613c1ec3ee8696745c (diff)
fix and optimize library aliases by making them refer instead of copy
-rw-r--r--src/jsifier.js11
-rw-r--r--src/library.js2
2 files changed, 8 insertions, 5 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 297af69e..63e762ad 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -198,7 +198,6 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
var shortident = item.ident.substr(1);
if (shortident in Library) {
function addFromLibrary(ident) {
- var me = arguments.callee;
if (ident in addedLibraryItems) return '';
// Don't replace implemented functions with library ones (which can happen when we add dependencies).
// Note: We don't return the dependencies here. Be careful not to end up where this matters
@@ -207,10 +206,15 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
addedLibraryItems[ident] = true;
var snippet = Library[ident];
var redirectedIdent = null;
+ var deps = Library[ident + '__deps'] || [];
+
if (typeof snippet === 'string') {
if (Library[snippet]) {
+ // Redirection for aliases. We include the parent, and at runtime make ourselves equal to it.
+ // This avoid having duplicate functions with identical content.
redirectedIdent = snippet;
- snippet = Library[snippet]; // redirection for aliases
+ deps.push(snippet);
+ snippet = '_' + snippet;
}
} else if (typeof snippet === 'object') {
// JSON.stringify removes functions, so we need to make sure they are added
@@ -244,7 +248,6 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
});
}
- var deps = Library[ident + '__deps'] || [];
if (redirectedIdent) {
deps = deps.concat(Library[redirectedIdent + '__deps'] || []);
}
@@ -254,7 +257,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
} else {
ident = '_' + ident;
}
- return 'var ' + ident + '=' + snippet + (deps ? '\n' + deps.map(addFromLibrary).join('\n') : '');
+ return (deps ? '\n' + deps.map(addFromLibrary).join('\n') : '') + 'var ' + ident + '=' + snippet + ';';
}
item.JS = addFromLibrary(shortident);
} else {
diff --git a/src/library.js b/src/library.js
index fe3f082e..a6a60f63 100644
--- a/src/library.js
+++ b/src/library.js
@@ -1276,7 +1276,7 @@ var Library = {
// stat.h
- __01stat64_: function() { return -1 },
+ __01stat64_: 'fstat',
__01fstat64_: 'fstat',
// locale.h