private static void PartiallyCopyTupleFast(PackedTuple source, PackedTuple target, int sourceStartIndex, int targetStartIndex, int length) { for (int i = 0; i < length; i++) { CopyPackedValue(source, sourceStartIndex + i, target, targetStartIndex + i); } }
private static void CopyPackedValue(PackedTuple source, int sourceIndex, PackedTuple target, int targetIndex) { var sourceDescriptor = source.PackedDescriptor.FieldDescriptors[sourceIndex]; var targetDescriptor = target.PackedDescriptor.FieldDescriptors[targetIndex]; var fieldState = source.GetFieldState(sourceDescriptor); if (!fieldState.IsAvailable()) { return; } if (fieldState.IsAvailableAndNull()) { target.SetValue(targetIndex, null); return; } var accessor = sourceDescriptor.Accessor; if (accessor != targetDescriptor.Accessor) { throw new InvalidOperationException(string.Format( Strings.ExInvalidCast, source.PackedDescriptor[sourceIndex], target.PackedDescriptor[targetIndex])); } target.SetFieldState(targetIndex, TupleFieldState.Available); accessor.CopyValue(source, sourceDescriptor, target, targetDescriptor); }
/// <summary> /// Copies a set of elements from <paramref name="sources"/> <see cref="Tuple"/>s /// to <paramref name="target"/> <see cref="Tuple"/> using /// specified target-to-source field index <paramref name="map"/>. /// </summary> /// <param name="sources">Source tuples to copy.</param> /// <param name="target">Tuple that receives the data.</param> /// <param name="map">Target-to-source field index map. /// Negative value in this map means "skip this element".</param> public static void CopyTo(this Tuple[] sources, Tuple target, Pair <int, int>[] map) { var haveSlowSource = false; var packedSources = new PackedTuple[sources.Length]; for (int i = 0; i < sources.Length; i++) { var packedSource = sources[i] as PackedTuple; if (packedSource == null) { haveSlowSource = true; break; } packedSources[i] = packedSource; } if (!haveSlowSource) { var packedTarget = target as PackedTuple; if (packedTarget != null) { CopyTupleArrayWithMappingFast(packedSources, packedTarget, map); return; } } CopyTupleArrayWithMappingSlow(sources, target, map); }
private static void CopyTupleWithMappingFast(PackedTuple source, PackedTuple target, int[] map) { for (int targetIndex = 0; targetIndex < map.Length; targetIndex++) { var sourceIndex = map[targetIndex]; if (sourceIndex >= 0) { CopyPackedValue(source, sourceIndex, target, targetIndex); } } }
private static void MergeTuplesPreferOriginFast(PackedTuple origin, PackedTuple difference, int startIndex, int length) { var bound = startIndex + length; for (int index = startIndex; index < bound; index++) { TupleFieldState fieldState; if (!origin.GetFieldState(index).IsAvailable()) { CopyPackedValue(difference, index, origin, index); } } }
private static void CopyTupleArrayWithMappingFast(PackedTuple[] sources, PackedTuple target, Pair <int, int>[] map) { for (int targetIndex = 0; targetIndex < map.Length; targetIndex++) { var sourceInfo = map[targetIndex]; var sourceTupleIndex = sourceInfo.First; var sourceFieldIndex = sourceInfo.Second; if (sourceTupleIndex >= 0 && sourceFieldIndex >= 0) { CopyPackedValue(sources[sourceTupleIndex], sourceFieldIndex, target, targetIndex); } } }