Skip to content

General code generation cleanups #3248

@mhevery

Description

@mhevery

Normalize string / No interpolation

  • Replace interpolate1 = "" "${componentName0 == null ? "" : componentName0}" "" with interpolate1 = " " + stringify(componentName0) + " "; NOTE: will require import of stringify method. I think ${} creates extra unneeded checks, so simple string concat + should be better in this case.

Inline assignments

  • take advantage of multiple assignments per line.

``` Dart``
_componentName0 = _gen.ChangeDetectionUtil.uninitialized();
_interpolate1 = _gen.ChangeDetectionUtil.uninitialized();
_directive_1_0 = _gen.ChangeDetectionUtil.uninitialized();
_directive_2_0 = _gen.ChangeDetectionUtil.uninitialized();


becomes:

``` Dart
 _componentName0 = _interpolate1 = _directive_1_0 = _directive_2_0 
       = _gen.ChangeDetectionUtil.uninitialized;
  • Also call dehydrateDirectives() from constructor so that we don't have to duplicate the code in the constructor.

Inline assignments and usages

  • inline where ever possible.
        _dispatcher.notifyOnBinding(currentProto.bindingRecord, interpolate1);
        _interpolate1 = interpolate1;

becomes

        _dispatcher.notifyOnBinding(currentProto.bindingRecord, _interpolate1 = interpolate1);

have notifyOnBinding helper

  • create viewSet in super. Notice that _dispatcher is always a View. This code is no longer abstract so we should use concrete names.
currentProto = _protos[1]
...     
change_interpolate1 = true;
_dispatcher.notifyOnBinding(currentProto.bindingRecord, interpolate1);
_interpolate1 = interpolate1;

becomes

        change_interpolate1 = viewSet(1, _interpolate1 = interpolate1);

which requires this method on superclass

  boolean viewSet(int index, dynamic value) {
    _view.notifyOnBinding(protos[index].bindingRecord, value);
    return true;
  }

looseNotIdentical

  • have loseNotIdentical which will allow us to change if (!_gen.looseIdentical(...)) to if (_gen.looseNotIdentical(...)). (its only one char, but it is everywhere)

inline context assignment

    var context = null;
    context = _context;

should be

    var context = _context;

Unused change_context

  • the code is never used in output
var change_context = false;

but is never read.

change uninitialized() method call to uninitialized static field

  • should save some chars

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions