| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 | 329 |
| 330 | 330 |
| 331 // Union is O(1) on simple bit unions, but O(n*m) on structured unions. | 331 // Union is O(1) on simple bit unions, but O(n*m) on structured unions. |
| 332 // TODO(rossberg): Should we use object sets somehow? Is it worth it? | 332 // TODO(rossberg): Should we use object sets somehow? Is it worth it? |
| 333 Type* Type::Union(Handle<Type> type1, Handle<Type> type2) { | 333 Type* Type::Union(Handle<Type> type1, Handle<Type> type2) { |
| 334 // Fast case: bit sets. | 334 // Fast case: bit sets. |
| 335 if (type1->is_bitset() && type2->is_bitset()) { | 335 if (type1->is_bitset() && type2->is_bitset()) { |
| 336 return from_bitset(type1->as_bitset() | type2->as_bitset()); | 336 return from_bitset(type1->as_bitset() | type2->as_bitset()); |
| 337 } | 337 } |
| 338 | 338 |
| 339 // Fast case: top or bottom types. |
| 340 if (type1->SameValue(Type::Any())) return *type1; |
| 341 if (type2->SameValue(Type::Any())) return *type2; |
| 342 if (type1->SameValue(Type::None())) return *type2; |
| 343 if (type2->SameValue(Type::None())) return *type1; |
| 344 |
| 339 // Semi-fast case: Unioned objects are neither involved nor produced. | 345 // Semi-fast case: Unioned objects are neither involved nor produced. |
| 340 if (!(type1->is_union() || type2->is_union())) { | 346 if (!(type1->is_union() || type2->is_union())) { |
| 341 if (type1->Is(type2)) return *type2; | 347 if (type1->Is(type2)) return *type2; |
| 342 if (type2->Is(type1)) return *type1; | 348 if (type2->Is(type1)) return *type1; |
| 343 } | 349 } |
| 344 | 350 |
| 345 // Slow case: may need to produce a Unioned object. | 351 // Slow case: may need to produce a Unioned object. |
| 346 Isolate* isolate = NULL; | 352 Isolate* isolate = NULL; |
| 347 int size = type1->is_bitset() || type2->is_bitset() ? 1 : 0; | 353 int size = type1->is_bitset() || type2->is_bitset() ? 1 : 0; |
| 348 if (!type1->is_bitset()) { | 354 if (!type1->is_bitset()) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 | 405 |
| 400 | 406 |
| 401 // Intersection is O(1) on simple bit unions, but O(n*m) on structured unions. | 407 // Intersection is O(1) on simple bit unions, but O(n*m) on structured unions. |
| 402 // TODO(rossberg): Should we use object sets somehow? Is it worth it? | 408 // TODO(rossberg): Should we use object sets somehow? Is it worth it? |
| 403 Type* Type::Intersect(Handle<Type> type1, Handle<Type> type2) { | 409 Type* Type::Intersect(Handle<Type> type1, Handle<Type> type2) { |
| 404 // Fast case: bit sets. | 410 // Fast case: bit sets. |
| 405 if (type1->is_bitset() && type2->is_bitset()) { | 411 if (type1->is_bitset() && type2->is_bitset()) { |
| 406 return from_bitset(type1->as_bitset() & type2->as_bitset()); | 412 return from_bitset(type1->as_bitset() & type2->as_bitset()); |
| 407 } | 413 } |
| 408 | 414 |
| 415 // Fast case: top or bottom types. |
| 416 if (type1->SameValue(Type::None())) return *type1; |
| 417 if (type2->SameValue(Type::None())) return *type2; |
| 418 if (type1->SameValue(Type::Any())) return *type2; |
| 419 if (type2->SameValue(Type::Any())) return *type1; |
| 420 |
| 409 // Semi-fast case: Unioned objects are neither involved nor produced. | 421 // Semi-fast case: Unioned objects are neither involved nor produced. |
| 410 if (!(type1->is_union() || type2->is_union())) { | 422 if (!(type1->is_union() || type2->is_union())) { |
| 411 if (type1->Is(type2)) return *type1; | 423 if (type1->Is(type2)) return *type1; |
| 412 if (type2->Is(type1)) return *type2; | 424 if (type2->Is(type1)) return *type2; |
| 413 } | 425 } |
| 414 | 426 |
| 415 // Slow case: may need to produce a Unioned object. | 427 // Slow case: may need to produce a Unioned object. |
| 416 Isolate* isolate = NULL; | 428 Isolate* isolate = NULL; |
| 417 int size = 0; | 429 int size = 0; |
| 418 if (!type1->is_bitset()) { | 430 if (!type1->is_bitset()) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 449 } | 461 } |
| 450 | 462 |
| 451 | 463 |
| 452 Type* Type::Optional(Handle<Type> type) { | 464 Type* Type::Optional(Handle<Type> type) { |
| 453 return type->is_bitset() | 465 return type->is_bitset() |
| 454 ? from_bitset(type->as_bitset() | kUndefined) | 466 ? from_bitset(type->as_bitset() | kUndefined) |
| 455 : Union(type, Undefined()->handle_via_isolate_of(*type)); | 467 : Union(type, Undefined()->handle_via_isolate_of(*type)); |
| 456 } | 468 } |
| 457 | 469 |
| 458 } } // namespace v8::internal | 470 } } // namespace v8::internal |
| OLD | NEW |