| 1085 | } |
| 1086 | |
| 1087 | bool CScriptArray::operator==(const CScriptArray &other) const |
| 1088 | { |
| 1089 | if( objType != other.objType ) |
| 1090 | return false; |
| 1091 | |
| 1092 | if( GetSize() != other.GetSize() ) |
| 1093 | return false; |
| 1094 | |
| 1095 | asIScriptContext *cmpContext = 0; |
| 1096 | bool isNested = false; |
| 1097 | |
| 1098 | if( subTypeId & ~asTYPEID_MASK_SEQNBR ) |
| 1099 | { |
| 1100 | // Try to reuse the active context |
| 1101 | cmpContext = asGetActiveContext(); |
| 1102 | if( cmpContext ) |
| 1103 | { |
| 1104 | if( cmpContext->GetEngine() == objType->GetEngine() && cmpContext->PushState() >= 0 ) |
| 1105 | isNested = true; |
| 1106 | else |
| 1107 | cmpContext = 0; |
| 1108 | } |
| 1109 | if( cmpContext == 0 ) |
| 1110 | { |
| 1111 | // TODO: Ideally this context would be retrieved from a pool, so we don't have to |
| 1112 | // create a new one everytime. We could keep a context with the array object |
| 1113 | // but that would consume a lot of resources as each context is quite heavy. |
| 1114 | cmpContext = objType->GetEngine()->CreateContext(); |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | // Check if all elements are equal |
| 1119 | bool isEqual = true; |
| 1120 | SArrayCache *cache = reinterpret_cast<SArrayCache*>(objType->GetUserData(ARRAY_CACHE)); |
| 1121 | for( asUINT n = 0; n < GetSize(); n++ ) |
| 1122 | if( !Equals(At(n), other.At(n), cmpContext, cache) ) |
| 1123 | { |
| 1124 | isEqual = false; |
| 1125 | break; |
| 1126 | } |
| 1127 | |
| 1128 | if( cmpContext ) |
| 1129 | { |
| 1130 | if( isNested ) |
| 1131 | { |
| 1132 | asEContextState state = cmpContext->GetState(); |
| 1133 | cmpContext->PopState(); |
| 1134 | if( state == asEXECUTION_ABORTED ) |
| 1135 | cmpContext->Abort(); |
| 1136 | } |
| 1137 | else |
| 1138 | cmpContext->Release(); |
| 1139 | } |
| 1140 | |
| 1141 | return isEqual; |
| 1142 | } |
| 1143 | |
| 1144 | // internal |
no test coverage detected