Optimize Array.Clear using SpanHelpers (#18101)
[platform/upstream/coreclr.git] / src / classlibnative / bcltype / arraynative.h
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 //
5 // File: ArrayNative.h
6 //
7
8 //
9 // ArrayNative
10 //  This file defines the native methods for the Array
11 //
12
13
14 #ifndef _ARRAYNATIVE_H_
15 #define _ARRAYNATIVE_H_
16
17 #include "fcall.h"
18
19 struct FCALLRuntimeFieldHandle
20 {
21     ReflectFieldObject *pFieldDONOTUSEDIRECTLY;
22 };
23 #define FCALL_RFH_TO_REFLECTFIELD(x) (x).pFieldDONOTUSEDIRECTLY
24
25 class ArrayNative
26 {
27 public:
28     static FCDECL1(INT32, GetRank, ArrayBase* pArray);
29     static FCDECL1(INT32, GetDataPtrOffsetInternal, ArrayBase* array);
30     static FCDECL2(INT32, GetLowerBound, ArrayBase* pArray, unsigned int dimension);
31     static FCDECL2(INT32, GetUpperBound, ArrayBase* pArray, unsigned int dimension);
32     static FCDECL1(INT32, GetLengthNoRank, ArrayBase* pArray);
33     static FCDECL1(INT64, GetLongLengthNoRank, ArrayBase* pArray);
34     static FCDECL2(INT32, GetLength, ArrayBase* pArray, unsigned int dimension);
35     static FCDECL1(void, Initialize, ArrayBase* pArray);
36
37     static FCDECL6(void, ArrayCopy, ArrayBase* m_pSrc, INT32 m_iSrcIndex, ArrayBase* m_pDst, INT32 m_iDstIndex, INT32 m_iLength, CLR_BOOL reliable);
38
39     static FCDECL5(void*, GetRawArrayGeometry, ArrayBase* pArray, UINT32* pNumComponents, UINT32* pElementSize, INT32* pLowerBound, CLR_BOOL* pContainsGCPointers);
40
41     // This method will create a new array of type type, with zero lower
42     // bounds and rank.
43     static FCDECL4(Object*, CreateInstance, void* elementTypeHandle, INT32 rank, INT32* pLengths, INT32* pBounds);
44
45     // This method will return a TypedReference to the array element
46     static FCDECL4(void, GetReference, ArrayBase* refThisUNSAFE, TypedByRef* elemRef, INT32 rank, INT32* pIndices);
47
48     // This set of methods will set a value in an array
49     static FCDECL2(void, SetValue, TypedByRef* target, Object* objUNSAFE);
50
51     // This method will initialize an array from a TypeHandle
52     // to a field.
53     static FCDECL2_IV(void, InitializeArray, ArrayBase* vArrayRef, FCALLRuntimeFieldHandle structField);
54
55 private:
56     // Helper for CreateInstance
57     static void CheckElementType(TypeHandle elementType);
58
59     // Return values for CanAssignArrayType
60     enum AssignArrayEnum
61     {
62         AssignWrongType,
63         AssignWillWork,
64         AssignMustCast,
65         AssignBoxValueClassOrPrimitive,
66         AssignUnboxValueClass,
67         AssignPrimitiveWiden,
68         AssignDontKnow,
69     };
70
71     // The following functions are all helpers for ArrayCopy
72     static AssignArrayEnum CanAssignArrayTypeNoGC(const BASEARRAYREF pSrc, const BASEARRAYREF pDest);
73     static AssignArrayEnum CanAssignArrayType(const BASEARRAYREF pSrc, const BASEARRAYREF pDest);
74     static void ArrayCopyNoTypeCheck(BASEARRAYREF pSrc, unsigned int srcIndex, BASEARRAYREF pDest, unsigned int destIndex, unsigned int length);
75     static void CastCheckEachElement(BASEARRAYREF pSrc, unsigned int srcIndex, BASEARRAYREF pDest, unsigned int destIndex, unsigned int length);
76     static void BoxEachElement(BASEARRAYREF pSrc, unsigned int srcIndex, BASEARRAYREF pDest, unsigned int destIndex, unsigned int length);
77     static void UnBoxEachElement(BASEARRAYREF pSrc, unsigned int srcIndex, BASEARRAYREF pDest, unsigned int destIndex, unsigned int length);
78     static void PrimitiveWiden(BASEARRAYREF pSrc, unsigned int srcIndex, BASEARRAYREF pDest, unsigned int destIndex, unsigned int length);
79
80 };
81
82 #endif // _ARRAYNATIVE_H_