| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 2772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2783 } | 2783 } |
| 2784 | 2784 |
| 2785 | 2785 |
| 2786 static Object* Runtime_StringEquals(Arguments args) { | 2786 static Object* Runtime_StringEquals(Arguments args) { |
| 2787 NoHandleAllocation ha; | 2787 NoHandleAllocation ha; |
| 2788 ASSERT(args.length() == 2); | 2788 ASSERT(args.length() == 2); |
| 2789 | 2789 |
| 2790 CONVERT_CHECKED(String, x, args[0]); | 2790 CONVERT_CHECKED(String, x, args[0]); |
| 2791 CONVERT_CHECKED(String, y, args[1]); | 2791 CONVERT_CHECKED(String, y, args[1]); |
| 2792 | 2792 |
| 2793 // This is very similar to String::Equals(String*) but that version | 2793 bool not_equal = !x->Equals(y); |
| 2794 // requires flattened strings as input, whereas we flatten the | 2794 // This is slightly convoluted because the value that signifies |
| 2795 // strings only if the fast cases fail. Note that this may fail, | 2795 // equality is 0 and inequality is 1 so we have to negate the result |
| 2796 // requiring a GC. String::Equals(String*) returns a bool and has | 2796 // from String::Equals. |
| 2797 // no way to signal a failure. | 2797 ASSERT(not_equal == 0 || not_equal == 1); |
| 2798 if (y == x) return Smi::FromInt(EQUAL); | 2798 STATIC_CHECK(EQUAL == 0); |
| 2799 if (x->IsSymbol() && y->IsSymbol()) return Smi::FromInt(NOT_EQUAL); | 2799 STATIC_CHECK(NOT_EQUAL == 1); |
| 2800 // Compare contents | 2800 return Smi::FromInt(not_equal); |
| 2801 int len = x->length(); | |
| 2802 if (len != y->length()) return Smi::FromInt(NOT_EQUAL); | |
| 2803 if (len == 0) return Smi::FromInt(EQUAL); | |
| 2804 | |
| 2805 // Handle one elment strings. | |
| 2806 if (x->Get(0) != y->Get(0)) return Smi::FromInt(NOT_EQUAL); | |
| 2807 if (len == 1) return Smi::FromInt(EQUAL); | |
| 2808 | |
| 2809 // Fast case: First, middle and last characters. | |
| 2810 if (x->Get(len>>1) != y->Get(len>>1)) return Smi::FromInt(NOT_EQUAL); | |
| 2811 if (x->Get(len - 1) != y->Get(len - 1)) return Smi::FromInt(NOT_EQUAL); | |
| 2812 | |
| 2813 x->TryFlatten(); | |
| 2814 y->TryFlatten(); | |
| 2815 | |
| 2816 static StringInputBuffer buf1; | |
| 2817 static StringInputBuffer buf2; | |
| 2818 buf1.Reset(x); | |
| 2819 buf2.Reset(y); | |
| 2820 while (buf1.has_more()) { | |
| 2821 if (buf1.GetNext() != buf2.GetNext()) | |
| 2822 return Smi::FromInt(NOT_EQUAL); | |
| 2823 } | |
| 2824 return Smi::FromInt(EQUAL); | |
| 2825 } | 2801 } |
| 2826 | 2802 |
| 2827 | 2803 |
| 2828 static Object* Runtime_NumberCompare(Arguments args) { | 2804 static Object* Runtime_NumberCompare(Arguments args) { |
| 2829 NoHandleAllocation ha; | 2805 NoHandleAllocation ha; |
| 2830 ASSERT(args.length() == 3); | 2806 ASSERT(args.length() == 3); |
| 2831 | 2807 |
| 2832 CONVERT_DOUBLE_CHECKED(x, args[0]); | 2808 CONVERT_DOUBLE_CHECKED(x, args[0]); |
| 2833 CONVERT_DOUBLE_CHECKED(y, args[1]); | 2809 CONVERT_DOUBLE_CHECKED(y, args[1]); |
| 2834 if (isnan(x) || isnan(y)) return args[2]; | 2810 if (isnan(x) || isnan(y)) return args[2]; |
| (...skipping 2639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5474 | 5450 |
| 5475 void Runtime::PerformGC(Object* result) { | 5451 void Runtime::PerformGC(Object* result) { |
| 5476 Failure* failure = Failure::cast(result); | 5452 Failure* failure = Failure::cast(result); |
| 5477 // Try to do a garbage collection; ignore it if it fails. The C | 5453 // Try to do a garbage collection; ignore it if it fails. The C |
| 5478 // entry stub will throw an out-of-memory exception in that case. | 5454 // entry stub will throw an out-of-memory exception in that case. |
| 5479 Heap::CollectGarbage(failure->requested(), failure->allocation_space()); | 5455 Heap::CollectGarbage(failure->requested(), failure->allocation_space()); |
| 5480 } | 5456 } |
| 5481 | 5457 |
| 5482 | 5458 |
| 5483 } } // namespace v8::internal | 5459 } } // namespace v8::internal |
| OLD | NEW |