Skip to content

Commit

Permalink
Revert "store trivial property values in prototype"
Browse files Browse the repository at this point in the history
This reverts commit 3e9a096.
  • Loading branch information
whoozle committed Sep 20, 2023
1 parent 8c96f91 commit e829a2c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 47 deletions.
19 changes: 3 additions & 16 deletions compiler/js/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,16 +358,6 @@ def generate_prototype(self, registry, ident_n = 1):
args.append(default_value)
r.append("%score.addProperty(%s)" %(ident, ", ".join(args)))

setup_on_changed = []

for target, value in self.assignments.items():
if target == "id" or target.endswith(".id"):
continue
else:
if "." not in target and lang.value_is_trivial(value):
r.append("%s$core._protoDefault(%s, '%s', %s)" %(ident, self.proto_name, target, value))
setup_on_changed.append("%s$core._setProtoDefault($this, '%s')" %(ident, target ))

for name, prop in self.enums.items():
values = prop.values

Expand Down Expand Up @@ -421,7 +411,6 @@ def put_in_prototype(handler):
for (path, name) in handlers:
assert not path
r.append("%s$core._protoOnChanged(%s, '%s', %s)" %(ident, self.proto_name, name, code))
setup_on_changed.append("%s$core._setProtoDefault($this, '%s')" %(ident, name))

for code, handlers in self.transform_handlers(registry, self.signal_handlers):
handlers = list(filter(put_in_prototype, handlers))
Expand Down Expand Up @@ -459,10 +448,10 @@ def put_in_prototype(handler):

setup_code = self.generate_setup_code(registry, '$this', '$c', ident_n + 2).strip()
b = '%s%s.$s.call($this, $c.$b); delete $c.$b' %(ident, self.base_proto_name)
if setup_code or setup_on_changed:
if setup_code:
generate = True
setup_code = '%s%s.$s = function($c) {\n\t\tvar $this = this;\n%s\n%s\n%s\n}' \
%(ident, self.proto_name, b, "\n".join(setup_on_changed), setup_code)
setup_code = '%s%s.$s = function($c) {\n\t\tvar $this = this;\n%s\n%s\n}' \
%(ident, self.proto_name, b, setup_code)

if generate:
r.append('')
Expand Down Expand Up @@ -651,8 +640,6 @@ def generate_setup_code(self, registry, parent, closure, ident_n = 1):
for target, value in self.assignments.items():
if target == "id":
continue
if self.prototype and "." not in target and lang.value_is_trivial(value):
continue
t = type(value)
#print self.name, target, value
target_owner, target_lvalue, target_prop = self.get_lvalue(registry, parent, target)
Expand Down
40 changes: 9 additions & 31 deletions core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,27 +643,20 @@ exports.addProperty = function(proto, type, name, defaultValue) {
defaultValue = getDefaultValueForType(type)
}

var protoDefault = '__default__' + name
var getDefaultValue = function(parent) {
if (protoDefault in parent)
return parent[protoDefault]
return defaultValue
}

var createStorage = function(newValue) {
var properties = this.__properties
var storage = properties[name]
if (storage === undefined) { //no storage
if (newValue === getDefaultValue(this)) //value === defaultValue, no storage allocation
if (newValue === defaultValue) //value === defaultValue, no storage allocation
return
storage = properties[name] = new PropertyStorage(getDefaultValue(this))
storage = properties[name] = new PropertyStorage(defaultValue)
}
return storage
}

var simpleGet = function() {
var storage = this.__properties[name]
return storage !== undefined? storage.getSimpleValue(getDefaultValue(this)): getDefaultValue(this)
return storage !== undefined? storage.getSimpleValue(defaultValue): defaultValue
}

var simpleSet = function(newValue) {
Expand All @@ -672,14 +665,14 @@ exports.addProperty = function(proto, type, name, defaultValue) {
if (storage === undefined)
return

storage.set(this, name, newValue, getDefaultValue(this), true)
storage.set(this, name, newValue, defaultValue, true)
}

var animatedGet = function() {
var storage = this.__properties[name]
return storage !== undefined?
storage.getCurrentValue(getDefaultValue(this)):
getDefaultValue(this)
storage.getCurrentValue(defaultValue):
defaultValue
}

var animatedSet = function(newValue) {
Expand All @@ -698,7 +691,7 @@ exports.addProperty = function(proto, type, name, defaultValue) {

storage.started = Date.now()

var src = storage.getCurrentValue(getDefaultValue(this))
var src = storage.getCurrentValue(defaultValue)
var dst = newValue

var self = this
Expand Down Expand Up @@ -728,7 +721,7 @@ exports.addProperty = function(proto, type, name, defaultValue) {
complete()
} else {
storage.interpolatedValue = convert(animation.interpolate(dst, src, t))
storage.callOnChanged(self, name, storage.getCurrentValue(getDefaultValue(self)), src)
storage.callOnChanged(self, name, storage.getCurrentValue(defaultValue), src)
storage.frameRequest = backend.requestAnimationFrame(nextFrame)
}
})
Expand All @@ -742,7 +735,7 @@ exports.addProperty = function(proto, type, name, defaultValue) {
animation.running = true
animation.complete = complete
}
storage.set(this, name, newValue, getDefaultValue(this), !animation)
storage.set(this, name, newValue, defaultValue, !animation)
// if ((!animation || !animation.running) && newValue === defaultValue)
// this.__properties[name] = undefined
}
Expand Down Expand Up @@ -838,21 +831,6 @@ $core._protoOnChanged = function(proto, name, callback)
$core._protoOnKey = function(proto, name, callback)
{ protoEvent('__key__', proto, name, callback) }

$core._protoDefault = function(proto, name, value)
{ proto['__default__' + name] = value }

$core._setProtoDefault = function(object, name) {
if (!('__properties' in object))
return

var value = object['__default__' + name]
if (value === undefined)
return

var storage = object.__properties[name]
_callOnChanged(object, name, value, storage? storage.onChanged: undefined)
}

$core.callMethod = function(obj, name) {
if (!obj)
return
Expand Down

0 comments on commit e829a2c

Please sign in to comment.