ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
Array::Ptr self = static_cast<Array::Ptr>(vframe->Self);
REQUIRE_NOT_NULL(self);
-
- std::set<Value> result;
-
- ObjectLock olock(self);
- for (const Value& item : self) {
- result.insert(item);
- }
-
- return Array::FromSet(result);
+ return self->Unique();
}
static void ArrayFreeze()
return msgbuf.str();
}
+Array::Ptr Array::Unique() const
+{
+ std::set<Value> result;
+
+ ObjectLock olock(this);
+
+ for (const Value& item : m_Data) {
+ result.insert(item);
+ }
+
+ return Array::FromSet(result);
+}
+
void Array::Freeze()
{
ObjectLock olock(this);
String ToString() const override;
+ Array::Ptr Unique() const;
void Freeze();
Value GetFieldByName(const String& field, bool sandboxed, const DebugInfo& debugInfo) const override;
base_array/resize
base_array/insert
base_array/remove
+ base_array/unique
base_array/foreach
base_array/clone
base_array/json
BOOST_CHECK(array->GetLength() == 0);
}
+BOOST_AUTO_TEST_CASE(unique)
+{
+ Array::Ptr array = new Array();
+ array->Add("group1");
+ array->Add("group2");
+ array->Add("group1");
+ array->Add("group2");
+
+ Array::Ptr result;
+
+ {
+ ObjectLock olock(array);
+ result = array->Unique();
+ }
+
+ BOOST_CHECK(result->GetLength() == 2);
+ result->Sort();
+
+ BOOST_CHECK(result->Get(0) == "group1");
+ BOOST_CHECK(result->Get(1) == "group2");
+}
BOOST_AUTO_TEST_CASE(foreach)
{
Array::Ptr array = new Array();