Chromium Code Reviews| Index: test/cctest/test-types.cc |
| diff --git a/test/cctest/test-types.cc b/test/cctest/test-types.cc |
| index 3448a841bde55b9aadbf59b365f06364207792fc..6840c9f1e0dd649261b76165bcb8fec67dbc6e9c 100644 |
| --- a/test/cctest/test-types.cc |
| +++ b/test/cctest/test-types.cc |
| @@ -25,7 +25,7 @@ |
| // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| -#include <list> |
| +#include <vector> |
| #include "cctest.h" |
| #include "types.h" |
| @@ -74,42 +74,27 @@ class Types { |
| ArrayConstant1 = Type::Constant(array, region); |
| ArrayConstant2 = Type::Constant(array, region); |
| - types.push_back(None); |
| - types.push_back(Any); |
| - types.push_back(Boolean); |
| - types.push_back(Null); |
| - types.push_back(Undefined); |
| - types.push_back(Number); |
| - types.push_back(SignedSmall); |
| - types.push_back(Signed32); |
| - types.push_back(Float); |
| - types.push_back(Name); |
| - types.push_back(UniqueName); |
| - types.push_back(String); |
| - types.push_back(InternalizedString); |
| - types.push_back(Symbol); |
| - types.push_back(Receiver); |
| - types.push_back(Object); |
| - types.push_back(Array); |
| - types.push_back(Function); |
| - types.push_back(Proxy); |
| - types.push_back(ObjectClass); |
| - types.push_back(ArrayClass); |
| - types.push_back(SmiConstant); |
| - types.push_back(Signed32Constant); |
| - types.push_back(ObjectConstant1); |
| - types.push_back(ObjectConstant2); |
| - types.push_back(ArrayConstant1); |
| - types.push_back(ArrayConstant2); |
| - for (int i = 0; i < 300; ++i) { |
| - types.push_back(Fuzz()); |
| - } |
| - |
| objects.push_back(smi); |
| objects.push_back(signed32); |
| objects.push_back(object1); |
| objects.push_back(object2); |
| objects.push_back(array); |
| + |
| + static const size_t kMaxTypes = 300; |
| + types.reserve(kMaxTypes); |
| +#define PUSH_BACK_BITSET_TYPE(type, value) \ |
| + types.push_back(Type::type(region)); |
| + BITSET_TYPE_LIST(PUSH_BACK_BITSET_TYPE) |
| +#undef PUSH_BACK_BITSET_TYPE |
| + types.push_back(ObjectClass); |
| + types.push_back(ArrayClass); |
| + for (ObjectVector::iterator it = objects.begin(); it != objects.end(); ++it) |
| + types.push_back(Type::Constant(*it, region)); |
| + while (types.size() < kMaxTypes) { |
| + size_t i = rand() % types.size(); |
|
rossberg
2014/04/09 13:59:10
I thought we shouldn't use rand... :)
Benedikt Meurer
2014/04/10 05:19:16
Another CL...
|
| + size_t j = rand() % types.size(); |
| + if (i != j) types.push_back(Type::Union(types[i], types[j], region)); |
| + } |
| } |
| TypeHandle Representation; |
| @@ -153,11 +138,11 @@ class Types { |
| Handle<i::JSObject> object2; |
| Handle<i::JSArray> array; |
| - typedef std::list<TypeHandle> TypeList; |
| - TypeList types; |
| + typedef std::vector<TypeHandle> TypeVector; |
| + TypeVector types; |
| - typedef std::list<Handle<i::Object> > ObjectList; |
| - ObjectList objects; |
| + typedef std::vector<Handle<i::Object> > ObjectVector; |
| + ObjectVector objects; |
| TypeHandle Of(Handle<i::Object> obj) { |
| return Type::Of(obj, region_); |
| @@ -179,49 +164,6 @@ class Types { |
| return Type::template Convert<Type2>(t, region_); |
| } |
| - TypeHandle Fuzz(int depth = 5) { |
| - switch (rand() % (depth == 0 ? 3 : 20)) { |
| - case 0: { // bitset |
| - int n = 0 |
| - #define COUNT_BITSET_TYPES(type, value) + 1 |
| - BITSET_TYPE_LIST(COUNT_BITSET_TYPES) |
| - #undef COUNT_BITSET_TYPES |
| - ; |
| - int i = rand() % n; |
| - #define PICK_BITSET_TYPE(type, value) \ |
| - if (i-- == 0) return Type::type(region_); |
| - BITSET_TYPE_LIST(PICK_BITSET_TYPE) |
| - #undef PICK_BITSET_TYPE |
| - UNREACHABLE(); |
| - } |
| - case 1: // class |
| - switch (rand() % 2) { |
| - case 0: return ObjectClass; |
| - case 1: return ArrayClass; |
| - } |
| - UNREACHABLE(); |
| - case 2: // constant |
| - switch (rand() % 6) { |
| - case 0: return SmiConstant; |
| - case 1: return Signed32Constant; |
| - case 2: return ObjectConstant1; |
| - case 3: return ObjectConstant2; |
| - case 4: return ArrayConstant1; |
| - case 5: return ArrayConstant2; |
| - } |
| - UNREACHABLE(); |
| - default: { // union |
| - int n = rand() % 10; |
| - TypeHandle type = None; |
| - for (int i = 0; i < n; ++i) { |
| - type = Type::Union(type, Fuzz(depth - 1), region_); |
| - } |
| - return type; |
| - } |
| - } |
| - UNREACHABLE(); |
| - } |
| - |
| private: |
| Region* region_; |
| }; |
| @@ -292,9 +234,9 @@ struct Tests : Rep { |
| HandleScope scope; |
| Zone zone; |
| Types<Type, TypeHandle, Region> T; |
| - typedef typename Types<Type, TypeHandle, Region>::TypeList::iterator |
| + typedef typename Types<Type, TypeHandle, Region>::TypeVector::iterator |
| TypeIterator; |
| - typedef typename Types<Type, TypeHandle, Region>::ObjectList::iterator |
| + typedef typename Types<Type, TypeHandle, Region>::ObjectVector::iterator |
| ObjectIterator; |
| Tests() : |
| @@ -1024,8 +966,8 @@ struct Tests : Rep { |
| void Convert() { |
| Types<Type2, TypeHandle2, Region2> T2( |
| Rep2::ToRegion(&zone, isolate), isolate); |
| - for (int i = 0; i < 100; ++i) { |
| - TypeHandle type = T.Fuzz(); |
| + for (TypeIterator it = T.types.begin(); it != T.types.end(); ++it) { |
| + TypeHandle type = *it; |
| CheckEqual(type, |
| T.template Convert<Type2>(T2.template Convert<Type>(type))); |
| } |