Revert "Few more small performance tweaks"

This reverts commit 0e00621840.
This commit is contained in:
impinball 2015-12-16 10:37:12 -05:00
parent c30bee5fa2
commit 75a3f0785c
3 changed files with 55 additions and 39 deletions

View file

@ -539,8 +539,7 @@
if (!keysDiffer) { if (!keysDiffer) {
forKeys(inst.data, function (attrs, i) { forKeys(inst.data, function (attrs, i) {
var cachedCell = inst.cached[i] var cachedCell = inst.cached[i]
return keysDiffer = return keysDiffer = cachedCell &&
cachedCell &&
cachedCell.attrs && cachedCell.attrs &&
cachedCell.attrs.key !== attrs.key cachedCell.attrs.key !== attrs.key
}) })
@ -602,7 +601,8 @@
case MOVE: case MOVE:
var changeElement = change.element var changeElement = change.element
if (inst.parent.childNodes[index] !== changeElement) { if (inst.parent.childNodes[index] !== changeElement &&
changeElement !== null) {
inst.parent.insertBefore( inst.parent.insertBefore(
changeElement, changeElement,
inst.parent.childNodes[index] || null inst.parent.childNodes[index] || null
@ -764,7 +764,7 @@
if (index > -1) { if (index > -1) {
return cached[index] return cached[index]
} else if (isFunction(controller)) { } else if (typeof controller === "function") {
return new controller() return new controller()
} else { } else {
return {} return {}
@ -790,19 +790,14 @@
} }
} }
// Shallow array compare, assumes strings // shallow array compare, sorts
function arraySortCompare(a, b) { function arraySortCompare(a, b) {
a.sort()
b.sort()
var len = a.length var len = a.length
if (len !== b.length) return false if (len !== b.length) return false
for (var i = 0; i < len; i++) {
// A string-integer map is used to simplify the algorithm from if (a[i] !== b[i]) return false
// 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
} }
return true return true
} }
@ -863,7 +858,8 @@
return $document.createElement(data.tag) return $document.createElement(data.tag)
} }
} else if (data.attrs.is) { } 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 { } else {
return $document.createElementNS(inst.ns, data.tag) return $document.createElementNS(inst.ns, data.tag)
} }
@ -897,7 +893,7 @@
function objectBuildChildren(inst, node) { function objectBuildChildren(inst, node) {
var children = inst.builder.data.children var children = inst.builder.data.children
if (children != null && children.length) { if (children != null && children.length !== 0) {
return objectMakeChild(inst, node, true) return objectMakeChild(inst, node, true)
} else { } else {
return children return children
@ -999,8 +995,22 @@
} }
function nodeHasBody(node) { 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 return node !== "AREA" &&
.test(node) 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) { function builderHandleNonexistentNodes(inst) {
@ -1043,9 +1053,10 @@
inst.editable.innerHTML = inst.data inst.editable.innerHTML = inst.data
} else { } else {
// was a trusted string // was a trusted string
if (nodes[0].nodeType === 1 || nodes.length > 1 || if (nodes[0].nodeType === 1 ||
isString(nodes[0].nodeValue) && nodes.length > 1 ||
/\s*/.test(nodes[0].nodeValue)) { (nodes[0].nodeValue.trim && !nodes[0].nodeValue.trim())
) {
clear(inst.cached.nodes, inst.cached) clear(inst.cached.nodes, inst.cached)
nodes = [$document.createTextNode(inst.data)] nodes = [$document.createTextNode(inst.data)]
} }
@ -1101,7 +1112,12 @@
} }
function shouldSetAttrDirectly(attr) { 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) { function trySetAttribute(attr, dataAttr, cachedAttr, node, namespace, tag) {
@ -1143,7 +1159,7 @@
// used as a string, but it's an object in js // used as a string, but it's an object in js
// //
// #348 // #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 // breaks in Chrome
if (tag !== "input" || node[attr] !== dataAttr) { if (tag !== "input" || node[attr] !== dataAttr) {
node[attr] = dataAttr node[attr] = dataAttr
@ -1159,7 +1175,7 @@
} catch (e) { } catch (e) {
// swallow IE's invalid argument errors to mimic HTML's // swallow IE's invalid argument errors to mimic HTML's
// fallback-to-doing-nothing-on-invalid-attributes behavior // 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) trySetSingle(attr, dataAttr, cachedAttr, node, namespace, tag)
} else if (attr === "value" && tag === "input" && } else if (attr === "value" && tag === "input" &&
// #348: dataAttr may not be a string, so use loose // #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) { // eslint-disable-line eqeqeq
node.value = dataAttr node.value = dataAttr
} }
@ -1346,7 +1362,7 @@
function getCellCacheKey(element) { function getCellCacheKey(element) {
var index = nodeCache.indexOf(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) { m.trust = function (value) {
@ -1452,7 +1468,7 @@
var lastRedrawCallTime = 0 var lastRedrawCallTime = 0
function actuallyPerformRedraw() { function actuallyPerformRedraw() {
if (lastRedrawId !== 0) $cancelAnimationFrame(lastRedrawId) if (lastRedrawId > 0) $cancelAnimationFrame(lastRedrawId)
lastRedrawId = $requestAnimationFrame(redraw, FRAME_BUDGET) lastRedrawId = $requestAnimationFrame(redraw, FRAME_BUDGET)
} }
@ -1814,8 +1830,8 @@
} }
function parseQueryString(str) { function parseQueryString(str) {
if (!str) return {} if (str === "" || str == null) return {}
if (str[0] === "?") str = str.slice(1) if (str.charAt(0) === "?") str = str.slice(1)
var pairs = str.split("&") var pairs = str.split("&")
var params = {} var params = {}
@ -2120,7 +2136,7 @@
script.src = options.url + script.src = options.url +
(options.url.indexOf("?") > 0 ? "&" : "?") + (options.url.indexOf("?") > 0 ? "&" : "?") +
(options.callbackKey || "callback") + (options.callbackKey ? options.callbackKey : "callback") +
"=" + callbackKey + "=" + callbackKey +
"&" + buildQueryString(options.data || {}) "&" + buildQueryString(options.data || {})
@ -2167,7 +2183,7 @@
data = options.data 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 " + throw new Error("Request data should be either be a string or " +
"FormData. Check the `serialize` option in `m.request`") "FormData. Check the `serialize` option in `m.request`")
} }
@ -2177,7 +2193,7 @@
} }
function ajax(options) { function ajax(options) {
if (options.dataType === "JSONP") { if (options.dataType && options.dataType.toLowerCase() === "jsonp") {
return getJsonp(options) return getJsonp(options)
} else { } else {
return runXhr(options) return runXhr(options)
@ -2219,15 +2235,15 @@
return jsonp.responseText return jsonp.responseText
} }
if (!options.dataType || options.dataType.toUpperCase() !== "JSONP") { if (!options.dataType || options.dataType.toLowerCase() !== "jsonp") {
options.dataType = "JSONP"
serialize = options.serialize || JSON.stringify serialize = options.serialize || JSON.stringify
deserialize = options.deserialize || JSON.parse deserialize = options.deserialize || JSON.parse
extract = options.extract || function (xhr) { extract = options.extract || function (xhr) {
if (xhr.responseText.length || deserialize !== JSON.parse) { if (xhr.responseText.length === 0 &&
return xhr.responseText deserialize === JSON.parse) {
} else {
return null return null
} else {
return xhr.responseText
} }
} }
} }

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