mirror of https://github.com/AMT-Cheif/drift.git
Avoid repeated allocations.
This commit is contained in:
parent
059108fff6
commit
1a1f53f60d
|
@ -157,19 +157,15 @@ class _BoundArguments {
|
|||
final List<Type> types;
|
||||
final List<TypedValue> parameters;
|
||||
|
||||
_BoundArguments(this.types, this.parameters);
|
||||
_BoundArguments(this.parameters)
|
||||
: types = parameters.map((p) => p.type).toList(growable: false);
|
||||
|
||||
factory _BoundArguments.ofDartArgs(List<Object?> args) {
|
||||
final types = <Type>[];
|
||||
final parameters = <TypedValue>[];
|
||||
|
||||
void add(TypedValue param) {
|
||||
types.add(param.type);
|
||||
parameters.add(param);
|
||||
}
|
||||
|
||||
for (final value in args) {
|
||||
add(switch (value) {
|
||||
final parameters = List<TypedValue>.generate(
|
||||
args.length,
|
||||
(i) {
|
||||
final value = args[i];
|
||||
return switch (value) {
|
||||
TypedValue() => value,
|
||||
null => TypedValue(Type.text, null),
|
||||
int() || BigInt() => TypedValue(Type.bigInteger, value),
|
||||
|
@ -178,10 +174,12 @@ class _BoundArguments {
|
|||
double() => TypedValue(Type.double, value),
|
||||
List<int>() => TypedValue(Type.byteArray, value),
|
||||
_ => throw ArgumentError.value(value, 'value', 'Unsupported type'),
|
||||
});
|
||||
}
|
||||
};
|
||||
},
|
||||
growable: false,
|
||||
);
|
||||
|
||||
return _BoundArguments(types, parameters);
|
||||
return _BoundArguments(parameters);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue