OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 int from, | 908 int from, |
909 int to, | 909 int to, |
910 bool followed_by_surrogate, | 910 bool followed_by_surrogate, |
911 int max_recursion, | 911 int max_recursion, |
912 bool* failure, | 912 bool* failure, |
913 bool* starts_with_surrogate) { | 913 bool* starts_with_surrogate) { |
914 if (from == to) return 0; | 914 if (from == to) return 0; |
915 int total = 0; | 915 int total = 0; |
916 bool dummy; | 916 bool dummy; |
917 while (true) { | 917 while (true) { |
918 if (input->IsAsciiRepresentation()) { | 918 if (input->IsOneByteRepresentation()) { |
919 *starts_with_surrogate = false; | 919 *starts_with_surrogate = false; |
920 return total + to - from; | 920 return total + to - from; |
921 } | 921 } |
922 switch (StringShape(input).representation_tag()) { | 922 switch (StringShape(input).representation_tag()) { |
923 case kConsStringTag: { | 923 case kConsStringTag: { |
924 ConsString* str = ConsString::cast(input); | 924 ConsString* str = ConsString::cast(input); |
925 String* first = str->first(); | 925 String* first = str->first(); |
926 String* second = str->second(); | 926 String* second = str->second(); |
927 int first_length = first->length(); | 927 int first_length = first->length(); |
928 if (first_length - from > to - first_length) { | 928 if (first_length - from > to - first_length) { |
(...skipping 12 matching lines...) Expand all Loading... |
941 followed_by_surrogate = right_starts_with_surrogate; | 941 followed_by_surrogate = right_starts_with_surrogate; |
942 input = first; | 942 input = first; |
943 to = first_length; | 943 to = first_length; |
944 } else { | 944 } else { |
945 // We only need the left hand side. | 945 // We only need the left hand side. |
946 input = first; | 946 input = first; |
947 } | 947 } |
948 } else { | 948 } else { |
949 if (first_length > from) { | 949 if (first_length > from) { |
950 // Left hand side is shorter. | 950 // Left hand side is shorter. |
951 if (first->IsAsciiRepresentation()) { | 951 if (first->IsOneByteRepresentation()) { |
952 total += first_length - from; | 952 total += first_length - from; |
953 *starts_with_surrogate = false; | 953 *starts_with_surrogate = false; |
954 starts_with_surrogate = &dummy; | 954 starts_with_surrogate = &dummy; |
955 input = second; | 955 input = second; |
956 from = 0; | 956 from = 0; |
957 to -= first_length; | 957 to -= first_length; |
958 } else if (second->IsAsciiRepresentation()) { | 958 } else if (second->IsOneByteRepresentation()) { |
959 followed_by_surrogate = false; | 959 followed_by_surrogate = false; |
960 total += to - first_length; | 960 total += to - first_length; |
961 input = first; | 961 input = first; |
962 to = first_length; | 962 to = first_length; |
963 } else if (max_recursion > 0) { | 963 } else if (max_recursion > 0) { |
964 bool right_starts_with_surrogate = false; | 964 bool right_starts_with_surrogate = false; |
965 // Recursing on the long one. This may fail. | 965 // Recursing on the long one. This may fail. |
966 total += Utf8LengthHelper(second, | 966 total += Utf8LengthHelper(second, |
967 0, | 967 0, |
968 to - first_length, | 968 to - first_length, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1077 data->next = prev_next_; | 1077 data->next = prev_next_; |
1078 data->limit = prev_limit_; | 1078 data->limit = prev_limit_; |
1079 #ifdef DEBUG | 1079 #ifdef DEBUG |
1080 handles_detached_ = true; | 1080 handles_detached_ = true; |
1081 #endif | 1081 #endif |
1082 return deferred; | 1082 return deferred; |
1083 } | 1083 } |
1084 | 1084 |
1085 | 1085 |
1086 } } // namespace v8::internal | 1086 } } // namespace v8::internal |
OLD | NEW |