浏览代码

Merge pull request #216 from UnityTech/remove_linq

remove potential performance-relevant linq expr
/main
GitHub 5 年前
当前提交
2dd1de55
共有 17 个文件被更改,包括 80 次插入47 次删除
  1. 28
      Runtime/flow/physical_shape_layer.cs
  2. 9
      Runtime/foundation/basic_types.cs
  3. 7
      Runtime/gestures/arena.cs
  4. 6
      Runtime/gestures/lsq_resolver.cs
  5. 5
      Runtime/gestures/multidrag.cs
  6. 6
      Runtime/gestures/multitap.cs
  7. 3
      Runtime/gestures/velocity_tracker.cs
  8. 9
      Runtime/rendering/table.cs
  9. 1
      Runtime/rendering/wrap.cs
  10. 14
      Runtime/ui/painting/txt/mesh_generator.cs
  11. 10
      Runtime/widgets/animated_switcher.cs
  12. 3
      Runtime/widgets/basic.cs
  13. 12
      Runtime/widgets/drag_target.cs
  14. 4
      Runtime/widgets/framework.cs
  15. 4
      Runtime/widgets/navigator.cs
  16. 2
      Runtime/widgets/scroll_controller.cs
  17. 4
      Runtime/widgets/sliver.cs

28
Runtime/flow/physical_shape_layer.cs


context.canvas.restore();
}
static Color _inAmbient;
static Color _inSpot;
static Color _ambientColor;
static Color _spotColor;
static Vector3 _zPlane = new Vector3();
static Vector3 _devLight = new Vector3();
public static void drawShadow(Canvas canvas, Path path, Color color, float elevation, bool transparentOccluder,
float dpr) {

Rect bounds = path.getBounds();
float shadow_x = (bounds.left + bounds.right) / 2f;
float shadow_y = bounds.top - 600.0f;
Color inAmbient = color.withAlpha((int) (kAmbientAlpha * color.alpha));
Color inSpot = color.withAlpha((int) (kSpotAlpha * color.alpha));
Color ambientColor = null;
Color spotColor = null;
ShadowUtils.computeTonalColors(inAmbient, inSpot, ref ambientColor, ref spotColor);
_inAmbient = color.withAlpha((int) (kAmbientAlpha * color.alpha));
_inSpot = color.withAlpha((int) (kSpotAlpha * color.alpha));
_ambientColor = null;
_spotColor = null;
ShadowUtils.computeTonalColors(_inAmbient, _inSpot, ref _ambientColor, ref _spotColor);
_zPlane.Set(0, 0, dpr * elevation);
_devLight.Set(shadow_x, shadow_y, dpr * kLightHeight);
new Vector3(0, 0, dpr * elevation),
new Vector3(shadow_x, shadow_y, dpr * kLightHeight),
_zPlane,
_devLight,
ambientColor,
spotColor,
_ambientColor,
_spotColor,
0
);
}

9
Runtime/foundation/basic_types.cs


public static T[] array<T>(this List<T> list) {
return NoAllocHelpersBridge<T>.ExtractArrayFromListT(list);
}
public static List<T> CreateRepeatedList<T>(T value, int length) {
List<T> newList = new List<T>(length);
for (int i = 0; i < length; i++) {
newList.Add(value);
}
return newList;
}
}
}

7
Runtime/gestures/arena.cs


D.assert(this._debugLogDiagnostic(
pointer, () => $"Winner: {state.members.First()}"));
state.members.First().acceptGesture(pointer);
state.members[0].acceptGesture(pointer);
for (int i = 1; i < state.members.Count; i++) {
state.members[i].rejectGesture(pointer);
}

D.assert(this._arenas[pointer] == state);
D.assert(!state.isOpen);
List<GestureArenaMember> members = state.members;
D.assert(members.Count == 1);
D.assert(state.members.Count == 1);
state.members.First().acceptGesture(pointer);
state.members[0].acceptGesture(pointer);
}
void _resolveInFavorOf(int pointer, _GestureArena state, GestureArenaMember member) {

6
Runtime/gestures/lsq_resolver.cs


internal _Vector(int size) {
this._offset = 0;
this._length = size;
this._elements = Enumerable.Repeat(0.0f, size).ToList();
this._elements = CollectionUtils.CreateRepeatedList(0.0f, size);
}
_Vector(List<float> values, int offset, int length) {

class _Matrix {
internal _Matrix(int rows, int cols) {
this._columns = cols;
this._elements = Enumerable.Repeat(0.0f, rows * cols).ToList();
this._elements = CollectionUtils.CreateRepeatedList(0.0f, rows * cols);
}
readonly int _columns;

public class PolynomialFit {
public PolynomialFit(int degree) {
this.coefficients = Enumerable.Repeat(0.0f, degree + 1).ToList();
this.coefficients = CollectionUtils.CreateRepeatedList(0.0f, degree + 1);
}
public readonly List<float> coefficients;

5
Runtime/gestures/multidrag.cs


using System;
using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.async;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;

public override void dispose() {
this._pointers.Keys.ToList().ForEach(this._removeState);
foreach (var key in this._pointers.Keys) {
this._removeState(key);
}
D.assert(this._pointers.isEmpty);
this._pointers = null;
base.dispose();

6
Runtime/gestures/multitap.cs


using System.Collections.Generic;
using System.Linq;
using RSG.Promises;
using Unity.UIWidgets.async;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;

}
void _clearTrackers() {
this._trackers.Values.ToList().Each(this._reject);
foreach (var tracker in this._trackers.Values) {
this._reject(tracker);
}
D.assert(this._trackers.isEmpty());
}

3
Runtime/gestures/velocity_tracker.cs


using System;
using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using UnityEngine;

const int _minSampleSize = 3;
readonly List<_PointAtTime> _samples =
Enumerable.Repeat<_PointAtTime>(null, _historySize).ToList();
CollectionUtils.CreateRepeatedList<_PointAtTime>(null, _historySize);
int _index = 0;

9
Runtime/rendering/table.cs


using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.painting;

D.assert(rows == null || rows >= 0);
D.assert(rows == null || children == null);
this._columns = columns ?? (children != null && children.isNotEmpty() ? children.First().Count : 0);
this._columns = columns ?? (children != null && children.isNotEmpty() ? children[0].Count : 0);
this._rows = rows ?? 0;
this._children = new List<RenderBox>();
for (int i = 0; i < this._columns * this._rows; i++) {

}
this._children.Clear();
this._columns = cells.isNotEmpty() ? cells.First().Count : 0;
this._columns = cells.isNotEmpty() ? cells[0].Count : 0;
this._rows = 0;
foreach (List<RenderBox> row in cells) {
this.addRow(row);

}
this._columnLefts = positions;
tableWidth = positions.Last() + widths.Last();
tableWidth = positions[positions.Count - 1] + widths[widths.Count - 1];
this._rowTops.Clear();
this._baselineDistance = null;

D.assert(this._rows == this._rowTops.Count - 1);
D.assert(this._columns == this._columnLefts.Count);
if (this.border != null) {
Rect borderRect = Rect.fromLTWH(offset.dx, offset.dy, this.size.width, this._rowTops.Last());
Rect borderRect = Rect.fromLTWH(offset.dx, offset.dy, this.size.width, this._rowTops[this._rowTops.Count - 1]);
List<float> rows = this._rowTops.GetRange(1, this._rowTops.Count - 2);
List<float> columns = this._columnLefts.GetRange(1, this._columnLefts.Count - 1);
this.border.paint(context.canvas, borderRect, rows: rows, columns: columns);

1
Runtime/rendering/wrap.cs


using System;
using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.painting;

14
Runtime/ui/painting/txt/mesh_generator.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace Unity.UIWidgets.ui {

public static int meshCount {
get { return _meshes.Count; }
}
static readonly List<MeshKey> _keysToRemove = new List<MeshKey>();
var keysToRemove = _meshes.Values.Where(info => info.timeToLive < _frameCount)
.Select(info => info.key).ToList();
foreach (var key in keysToRemove) {
_keysToRemove.Clear();
foreach (var info in _meshes.Values) {
if (info.timeToLive < _frameCount) {
_keysToRemove.Add(info.key);
}
}
foreach (var key in _keysToRemove) {
_meshes.Remove(key);
}
}

10
Runtime/widgets/animated_switcher.cs


}
void _rebuildOutgoingWidgetsIfNeeded() {
this._outgoingWidgets = this._outgoingWidgets ?? new List<Widget>(
this._outgoingEntries.Select((_ChildEntry entry) => entry.transition)
);
if (this._outgoingWidgets == null) {
this._outgoingWidgets = new List<Widget>(this._outgoingEntries.Count);
foreach (_ChildEntry entry in this._outgoingEntries) {
this._outgoingWidgets.Add(entry.transition);
}
}
D.assert(this._outgoingEntries.Count == this._outgoingWidgets.Count);
D.assert(this._outgoingEntries.isEmpty() ||
this._outgoingEntries.Last().transition == this._outgoingWidgets.Last());

3
Runtime/widgets/basic.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UIWidgets.Runtime.rendering;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;

}
public static List<RepaintBoundary> wrapAll(List<Widget> widgets) {
List<RepaintBoundary> result = Enumerable.Repeat((RepaintBoundary) null, widgets.Count).ToList();
List<RepaintBoundary> result = CollectionUtils.CreateRepeatedList<RepaintBoundary>(null, widgets.Count);
for (int i = 0; i < result.Count; ++i) {
result[i] = wrap(widgets[i], i);
}

12
Runtime/widgets/drag_target.cs


using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.painting;

static class _DragUtils {
public static List<T> _mapAvatarsToData<T>(List<_DragAvatar<T>> avatars) {
return avatars.Select(avatar => avatar.data).ToList();
List<T> ret = new List<T>(avatars.Count);
foreach (var avatar in avatars) {
ret.Add(avatar.data);
}
return ret;
}
}

HitTestResult result = new HitTestResult();
WidgetsBinding.instance.hitTest(result, globalPosition + this.feedbackOffset);
List<_DragTargetState<T>> targets = this._getDragTargets(result.path.ToList());
List<_DragTargetState<T>> targets = this._getDragTargets(result.path);
bool listsMatch = false;
if (targets.Count >= this._enteredTargets.Count && this._enteredTargets.isNotEmpty()) {

this._activeTarget = newTarget;
}
List<_DragTargetState<T>> _getDragTargets(List<HitTestEntry> path) {
List<_DragTargetState<T>> _getDragTargets(IList<HitTestEntry> path) {
List<_DragTargetState<T>> ret = new List<_DragTargetState<T>>();
foreach (HitTestEntry entry in path) {

4
Runtime/widgets/framework.cs


var newChildren = oldChildren.Count == newWidgets.Count
? oldChildren
: Enumerable.Repeat((Element) null, newWidgets.Count).ToList();
: CollectionUtils.CreateRepeatedList<Element>(null, newWidgets.Count);
Element previousChild = null;

public override void mount(Element parent, object newSlot) {
base.mount(parent, newSlot);
this._children = Enumerable.Repeat((Element) null, this.widget.children.Count).ToList();
this._children = CollectionUtils.CreateRepeatedList<Element>(null, this.widget.children.Count);
Element previousChild = null;
for (int i = 0; i < this._children.Count; i += 1) {
Element newChild = this.inflateWidget(this.widget.children[i], previousChild);

4
Runtime/widgets/navigator.cs


});
}
this._activePointers.ToList().ForEach(WidgetsBinding.instance.cancelPointer);
foreach (var pointer in this._activePointers) {
WidgetsBinding.instance.cancelPointer(pointer);
}
}
public override Widget build(BuildContext context) {

2
Runtime/widgets/scroll_controller.cs


Curve curve
) {
D.assert(this._positions.isNotEmpty(), () => "ScrollController not attached to any scroll views.");
List<IPromise> animations = Enumerable.Repeat((IPromise) null, this._positions.Count).ToList();
List<IPromise> animations = CollectionUtils.CreateRepeatedList<IPromise>(null, this._positions.Count);
for (int i = 0; i < this._positions.Count; i += 1) {
animations[i] = this._positions[i].animateTo(to, duration: duration, curve: curve);
}

4
Runtime/widgets/sliver.cs


public override void visitChildren(ElementVisitor visitor) {
D.assert(!this._childElements.Values.Any(child => child == null));
this._childElements.Values.ToList().ForEach(e => visitor(e));
foreach (var e in this._childElements.Values) {
visitor(e);
}
}
public override void debugVisitOnstageChildren(ElementVisitor visitor) {

正在加载...
取消
保存