Chromium Code Reviews| 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 7171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7182 Vector<const char> ToAsciiVector() { | 7182 Vector<const char> ToAsciiVector() { |
| 7183 ASSERT_EQ(ASCII, state_); | 7183 ASSERT_EQ(ASCII, state_); |
| 7184 return Vector<const char>::cast(buffer_); | 7184 return Vector<const char>::cast(buffer_); |
| 7185 } | 7185 } |
| 7186 // Return the two-byte content of the string. Only use if IsTwoByte() | 7186 // Return the two-byte content of the string. Only use if IsTwoByte() |
| 7187 // returns true. | 7187 // returns true. |
| 7188 Vector<const uc16> ToUC16Vector() { | 7188 Vector<const uc16> ToUC16Vector() { |
| 7189 ASSERT_EQ(TWO_BYTE, state_); | 7189 ASSERT_EQ(TWO_BYTE, state_); |
| 7190 return Vector<const uc16>::cast(buffer_); | 7190 return Vector<const uc16>::cast(buffer_); |
| 7191 } | 7191 } |
| 7192 // Return the character length of the string. | |
| 7193 unsigned Length() const { | |
| 7194 if (state_ == ASCII) return buffer_.length(); | |
| 7195 if (state_ == TWO_BYTE) return buffer_.length() / 2; | |
|
Yang
2012/11/26 08:45:30
you could do an
if (state_ == ASCII) {
...
} els
| |
| 7196 UNREACHABLE(); | |
| 7197 return 0; // Placate compiler. | |
| 7198 } | |
| 7192 | 7199 |
| 7193 private: | 7200 private: |
| 7194 enum State { NON_FLAT, ASCII, TWO_BYTE }; | 7201 enum State { NON_FLAT, ASCII, TWO_BYTE }; |
| 7195 | 7202 |
| 7196 // Constructors only used by String::GetFlatContent(). | 7203 // Constructors only used by String::GetFlatContent(). |
| 7197 explicit FlatContent(Vector<const char> chars) | 7204 explicit FlatContent(Vector<const char> chars) |
| 7198 : buffer_(Vector<const byte>::cast(chars)), | 7205 : buffer_(Vector<const byte>::cast(chars)), |
| 7199 state_(ASCII) { } | 7206 state_(ASCII) { } |
| 7200 explicit FlatContent(Vector<const uc16> chars) | 7207 explicit FlatContent(Vector<const uc16> chars) |
| 7201 : buffer_(Vector<const byte>::cast(chars)), | 7208 : buffer_(Vector<const byte>::cast(chars)), |
| (...skipping 1801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9003 } else { | 9010 } else { |
| 9004 value &= ~(1 << bit_position); | 9011 value &= ~(1 << bit_position); |
| 9005 } | 9012 } |
| 9006 return value; | 9013 return value; |
| 9007 } | 9014 } |
| 9008 }; | 9015 }; |
| 9009 | 9016 |
| 9010 } } // namespace v8::internal | 9017 } } // namespace v8::internal |
| 9011 | 9018 |
| 9012 #endif // V8_OBJECTS_H_ | 9019 #endif // V8_OBJECTS_H_ |
| OLD | NEW |