Revert "Few more small performance tweaks"
This reverts commit 0e00621840.
This commit is contained in:
parent
c30bee5fa2
commit
75a3f0785c
3 changed files with 55 additions and 39 deletions
90
mithril.js
90
mithril.js
|
|
@ -539,8 +539,7 @@
|
|||
if (!keysDiffer) {
|
||||
forKeys(inst.data, function (attrs, i) {
|
||||
var cachedCell = inst.cached[i]
|
||||
return keysDiffer =
|
||||
cachedCell &&
|
||||
return keysDiffer = cachedCell &&
|
||||
cachedCell.attrs &&
|
||||
cachedCell.attrs.key !== attrs.key
|
||||
})
|
||||
|
|
@ -602,7 +601,8 @@
|
|||
|
||||
case MOVE:
|
||||
var changeElement = change.element
|
||||
if (inst.parent.childNodes[index] !== changeElement) {
|
||||
if (inst.parent.childNodes[index] !== changeElement &&
|
||||
changeElement !== null) {
|
||||
inst.parent.insertBefore(
|
||||
changeElement,
|
||||
inst.parent.childNodes[index] || null
|
||||
|
|
@ -764,7 +764,7 @@
|
|||
|
||||
if (index > -1) {
|
||||
return cached[index]
|
||||
} else if (isFunction(controller)) {
|
||||
} else if (typeof controller === "function") {
|
||||
return new controller()
|
||||
} else {
|
||||
return {}
|
||||
|
|
@ -790,19 +790,14 @@
|
|||
}
|
||||
}
|
||||
|
||||
// Shallow array compare, assumes strings
|
||||
// shallow array compare, sorts
|
||||
function arraySortCompare(a, b) {
|
||||
a.sort()
|
||||
b.sort()
|
||||
var len = a.length
|
||||
if (len !== b.length) return false
|
||||
|
||||
// A string-integer map is used to simplify the algorithm from
|
||||
// two `O(n * log(n))` loops + an `O(n)` loop to just two O(n) loops
|
||||
// with constant-time (or a super cheap `log(n)`) string key lookup.
|
||||
var i = 0
|
||||
var cache = Object.create(null)
|
||||
while (i < len) cache[b[i]] = i++
|
||||
while (i !== 0) {
|
||||
if (cache[a[--i]] === undefined) return false
|
||||
for (var i = 0; i < len; i++) {
|
||||
if (a[i] !== b[i]) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
@ -863,7 +858,8 @@
|
|||
return $document.createElement(data.tag)
|
||||
}
|
||||
} else if (data.attrs.is) {
|
||||
return $document.createElementNS(inst.ns, data.tag, data.attrs.is)
|
||||
return $document.createElementNS(inst.ns, data.tag,
|
||||
data.attrs.is)
|
||||
} else {
|
||||
return $document.createElementNS(inst.ns, data.tag)
|
||||
}
|
||||
|
|
@ -897,7 +893,7 @@
|
|||
|
||||
function objectBuildChildren(inst, node) {
|
||||
var children = inst.builder.data.children
|
||||
if (children != null && children.length) {
|
||||
if (children != null && children.length !== 0) {
|
||||
return objectMakeChild(inst, node, true)
|
||||
} else {
|
||||
return children
|
||||
|
|
@ -999,8 +995,22 @@
|
|||
}
|
||||
|
||||
function nodeHasBody(node) {
|
||||
return !/^(AREA|BASE|BR|COL|COMMAND|EMBED|HR|IMG|INPUT|KEYGEN|LINK|META|PARAM|SOURCE|TRACK|WBR)$/ // eslint-disable-line max-len
|
||||
.test(node)
|
||||
return node !== "AREA" &&
|
||||
node !== "BASE" &&
|
||||
node !== "BR" &&
|
||||
node !== "COL" &&
|
||||
node !== "COMMAND" &&
|
||||
node !== "EMBED" &&
|
||||
node !== "HR" &&
|
||||
node !== "IMG" &&
|
||||
node !== "INPUT" &&
|
||||
node !== "KEYGEN" &&
|
||||
node !== "LINK" &&
|
||||
node !== "META" &&
|
||||
node !== "PARAM" &&
|
||||
node !== "SOURCE" &&
|
||||
node !== "TRACK" &&
|
||||
node !== "WBR"
|
||||
}
|
||||
|
||||
function builderHandleNonexistentNodes(inst) {
|
||||
|
|
@ -1043,9 +1053,10 @@
|
|||
inst.editable.innerHTML = inst.data
|
||||
} else {
|
||||
// was a trusted string
|
||||
if (nodes[0].nodeType === 1 || nodes.length > 1 ||
|
||||
isString(nodes[0].nodeValue) &&
|
||||
/\s*/.test(nodes[0].nodeValue)) {
|
||||
if (nodes[0].nodeType === 1 ||
|
||||
nodes.length > 1 ||
|
||||
(nodes[0].nodeValue.trim && !nodes[0].nodeValue.trim())
|
||||
) {
|
||||
clear(inst.cached.nodes, inst.cached)
|
||||
nodes = [$document.createTextNode(inst.data)]
|
||||
}
|
||||
|
|
@ -1101,7 +1112,12 @@
|
|||
}
|
||||
|
||||
function shouldSetAttrDirectly(attr) {
|
||||
return !/^(list|style|form|type|width|height)$/.test(attr)
|
||||
return attr !== "list" &&
|
||||
attr !== "style" &&
|
||||
attr !== "form" &&
|
||||
attr !== "type" &&
|
||||
attr !== "width" &&
|
||||
attr !== "height"
|
||||
}
|
||||
|
||||
function trySetAttribute(attr, dataAttr, cachedAttr, node, namespace, tag) {
|
||||
|
|
@ -1143,7 +1159,7 @@
|
|||
// used as a string, but it's an object in js
|
||||
//
|
||||
// #348
|
||||
// don't set the value if not needed, otherwise cursor placement
|
||||
// don't set the value if not needed otherwise cursor placement
|
||||
// breaks in Chrome
|
||||
if (tag !== "input" || node[attr] !== dataAttr) {
|
||||
node[attr] = dataAttr
|
||||
|
|
@ -1159,7 +1175,7 @@
|
|||
} catch (e) {
|
||||
// swallow IE's invalid argument errors to mimic HTML's
|
||||
// fallback-to-doing-nothing-on-invalid-attributes behavior
|
||||
if (!/\bInvalid argument\b/.test(e.message)) throw e
|
||||
if (e.message.indexOf("Invalid argument") < 0) throw e
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1171,7 +1187,7 @@
|
|||
trySetSingle(attr, dataAttr, cachedAttr, node, namespace, tag)
|
||||
} else if (attr === "value" && tag === "input" &&
|
||||
// #348: dataAttr may not be a string, so use loose
|
||||
// comparison (i.e. identity not required).
|
||||
// comparison
|
||||
node.value != dataAttr) { // eslint-disable-line eqeqeq
|
||||
node.value = dataAttr
|
||||
}
|
||||
|
|
@ -1346,7 +1362,7 @@
|
|||
|
||||
function getCellCacheKey(element) {
|
||||
var index = nodeCache.indexOf(element)
|
||||
return index >= 0 ? index : nodeCache.push(element) - 1
|
||||
return index < 0 ? nodeCache.push(element) - 1 : index
|
||||
}
|
||||
|
||||
m.trust = function (value) {
|
||||
|
|
@ -1452,7 +1468,7 @@
|
|||
var lastRedrawCallTime = 0
|
||||
|
||||
function actuallyPerformRedraw() {
|
||||
if (lastRedrawId !== 0) $cancelAnimationFrame(lastRedrawId)
|
||||
if (lastRedrawId > 0) $cancelAnimationFrame(lastRedrawId)
|
||||
lastRedrawId = $requestAnimationFrame(redraw, FRAME_BUDGET)
|
||||
}
|
||||
|
||||
|
|
@ -1814,8 +1830,8 @@
|
|||
}
|
||||
|
||||
function parseQueryString(str) {
|
||||
if (!str) return {}
|
||||
if (str[0] === "?") str = str.slice(1)
|
||||
if (str === "" || str == null) return {}
|
||||
if (str.charAt(0) === "?") str = str.slice(1)
|
||||
|
||||
var pairs = str.split("&")
|
||||
var params = {}
|
||||
|
|
@ -2120,7 +2136,7 @@
|
|||
|
||||
script.src = options.url +
|
||||
(options.url.indexOf("?") > 0 ? "&" : "?") +
|
||||
(options.callbackKey || "callback") +
|
||||
(options.callbackKey ? options.callbackKey : "callback") +
|
||||
"=" + callbackKey +
|
||||
"&" + buildQueryString(options.data || {})
|
||||
|
||||
|
|
@ -2167,7 +2183,7 @@
|
|||
data = options.data
|
||||
}
|
||||
|
||||
if (data && !isString(data) && !(data instanceof window.FormData)) {
|
||||
if (data && !isString(data) && data.constructor !== window.FormData) {
|
||||
throw new Error("Request data should be either be a string or " +
|
||||
"FormData. Check the `serialize` option in `m.request`")
|
||||
}
|
||||
|
|
@ -2177,7 +2193,7 @@
|
|||
}
|
||||
|
||||
function ajax(options) {
|
||||
if (options.dataType === "JSONP") {
|
||||
if (options.dataType && options.dataType.toLowerCase() === "jsonp") {
|
||||
return getJsonp(options)
|
||||
} else {
|
||||
return runXhr(options)
|
||||
|
|
@ -2219,15 +2235,15 @@
|
|||
return jsonp.responseText
|
||||
}
|
||||
|
||||
if (!options.dataType || options.dataType.toUpperCase() !== "JSONP") {
|
||||
options.dataType = "JSONP"
|
||||
if (!options.dataType || options.dataType.toLowerCase() !== "jsonp") {
|
||||
serialize = options.serialize || JSON.stringify
|
||||
deserialize = options.deserialize || JSON.parse
|
||||
extract = options.extract || function (xhr) {
|
||||
if (xhr.responseText.length || deserialize !== JSON.parse) {
|
||||
return xhr.responseText
|
||||
} else {
|
||||
if (xhr.responseText.length === 0 &&
|
||||
deserialize === JSON.parse) {
|
||||
return null
|
||||
} else {
|
||||
return xhr.responseText
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
mithril.min.js
vendored
2
mithril.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue