浏览代码

Fix NoAllocHelpers.

/main
kg 5 年前
当前提交
1e87a3b3
共有 11 个文件被更改,包括 73 次插入76 次删除
  1. 4
      Runtime/Unity.UIWidgets.asmdef
  2. 8
      Runtime/foundation/basic_types.cs
  3. 7
      Runtime/ui/txt/linebreaker.cs
  4. 2
      Runtime/InternalBridge/NoAllocHelpersBridge.cs.meta
  5. 8
      Runtime/InternalBridge.meta
  6. 12
      Runtime/InternalBridge/InternalBridge.asmdef
  7. 7
      Runtime/InternalBridge/InternalBridge.asmdef.meta
  8. 35
      Runtime/InternalBridge/NoAllocHelpersBridge.cs
  9. 66
      Runtime/ui/painting/NoAllocHelpers.cs
  10. 0
      /Runtime/InternalBridge/NoAllocHelpersBridge.cs.meta

4
Runtime/Unity.UIWidgets.asmdef


{
"name": "Unity.UIWidgets",
"references": [],
"references": [
"Unity.InternalAPIEngineBridge.024"
],
"optionalUnityReferences": [],
"includePlatforms": [],
"excludePlatforms": [],

8
Runtime/foundation/basic_types.cs


using System;
using System.Collections.Generic;
using System.Linq;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.InternalBridge;
using UnityEngine;
using Object = UnityEngine.Object;

}
public static void reset<T>(this List<T> list, int size) {
NoAllocHelpers<T>.EnsureListElemCount(list, size);
NoAllocHelpersBridge<T>.EnsureListElemCount(list, size);
var array = NoAllocHelpers<T>.ExtractArrayFromListT(list);
var array = NoAllocHelpersBridge<T>.ExtractArrayFromListT(list);
return NoAllocHelpers<T>.ExtractArrayFromListT(list);
return NoAllocHelpersBridge<T>.ExtractArrayFromListT(list);
}
}
}

7
Runtime/ui/txt/linebreaker.cs


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

public void resize(int size) {
if (this._charWidths.Count < size) {
NoAllocHelpers<float>.ResizeList(this._charWidths, size);
NoAllocHelpersBridge<float>.ResizeList(this._charWidths, size);
}
}

2
Runtime/InternalBridge/NoAllocHelpersBridge.cs.meta


fileFormatVersion: 2
guid: 2facb9d73ce7146b9942f8e22d4a04a3
guid: ae100515a41a04d9f8426e6d7c4b2d04
MonoImporter:
externalObjects: {}
serializedVersion: 2

8
Runtime/InternalBridge.meta


fileFormatVersion: 2
guid: 6692331a428d6455c97baf446a850594
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

12
Runtime/InternalBridge/InternalBridge.asmdef


{
"name": "Unity.InternalAPIEngineBridge.024",
"references": [],
"optionalUnityReferences": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": []
}

7
Runtime/InternalBridge/InternalBridge.asmdef.meta


fileFormatVersion: 2
guid: 4c951e9ffe25e41eabcc32758a061e70
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

35
Runtime/InternalBridge/NoAllocHelpersBridge.cs


using System.Collections.Generic;
namespace Unity.UIWidgets.InternalBridge {
public static class NoAllocHelpersBridge<T> {
public static T[] ExtractArrayFromListT(List<T> list) {
return UnityEngine.NoAllocHelpers.ExtractArrayFromListT(list);
}
public static void ResizeList(List<T> list, int size) {
if (size < list.Count) {
list.RemoveRange(size, list.Count - size);
return;
}
if (size == list.Count) {
return;
}
if (list.Capacity < size) {
list.Capacity = size;
}
UnityEngine.NoAllocHelpers.ResizeList(list, size);
}
public static void EnsureListElemCount(List<T> list, int size) {
list.Clear();
if (list.Capacity < size) {
list.Capacity = size;
}
ResizeList(list, size);
}
}
}

66
Runtime/ui/painting/NoAllocHelpers.cs


using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
namespace Unity.UIWidgets.ui {
public static class NoAllocHelpers<T> {
static Func<List<T>, T[]> _extractArrayFromListDelegate;
static Action<List<T>, int> _resizeListDelegate;
public static T[] ExtractArrayFromListT(List<T> list) {
if (_extractArrayFromListDelegate == null) {
var ass = Assembly.GetAssembly(typeof(Mesh));
var type = ass.GetType("UnityEngine.NoAllocHelpers");
var methodInfo = type.GetMethod(
"ExtractArrayFromListT",
BindingFlags.Static | BindingFlags.Public)
.MakeGenericMethod(typeof(T));
_extractArrayFromListDelegate = (Func<List<T>, T[]>)
Delegate.CreateDelegate(typeof(Func<List<T>, T[]>), methodInfo);
}
return _extractArrayFromListDelegate(list);
}
public static void ResizeList(List<T> list, int size) {
if (size < list.Count) {
list.RemoveRange(size, list.Count - size);
return;
}
if (size == list.Count) {
return;
}
if (list.Capacity < size) {
list.Capacity = size;
}
if (_resizeListDelegate == null) {
var ass = Assembly.GetAssembly(typeof(Mesh)); // any class in UnityEngine
var type = ass.GetType("UnityEngine.NoAllocHelpers");
var methodInfo = type.GetMethod(
"ResizeList",
BindingFlags.Static | BindingFlags.Public)
.MakeGenericMethod(typeof(T));
_resizeListDelegate = (Action<List<T>, int>)
Delegate.CreateDelegate(typeof(Action<List<T>, int>), methodInfo);
}
_resizeListDelegate(list, size);
}
public static void EnsureListElemCount(List<T> list, int size) {
list.Clear();
if (list.Capacity < size) {
list.Capacity = size;
}
ResizeList(list, size);
}
}
}

/Runtime/ui/painting/NoAllocHelpers.cs.meta → /Runtime/InternalBridge/NoAllocHelpersBridge.cs.meta

正在加载...
取消
保存