Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: src/objects.h

Issue 225823003: Implement handlified String::Equals and Name::Equals. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: refactored StringToDouble Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/mips/lithium-codegen-mips.cc ('k') | src/objects.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 6451 matching lines...) Expand 10 before | Expand all | Expand 10 after
6462 // Returns the number of slots allocated for the initial properties 6462 // Returns the number of slots allocated for the initial properties
6463 // backing storage for instances of this map. 6463 // backing storage for instances of this map.
6464 int InitialPropertiesLength() { 6464 int InitialPropertiesLength() {
6465 return pre_allocated_property_fields() + unused_property_fields() - 6465 return pre_allocated_property_fields() + unused_property_fields() -
6466 inobject_properties(); 6466 inobject_properties();
6467 } 6467 }
6468 6468
6469 // Casting. 6469 // Casting.
6470 static inline Map* cast(Object* obj); 6470 static inline Map* cast(Object* obj);
6471 6471
6472 // Locate an accessor in the instance descriptor.
6473 AccessorDescriptor* FindAccessor(Name* name);
6474
6475 // Code cache operations. 6472 // Code cache operations.
6476 6473
6477 // Clears the code cache. 6474 // Clears the code cache.
6478 inline void ClearCodeCache(Heap* heap); 6475 inline void ClearCodeCache(Heap* heap);
6479 6476
6480 // Update code cache. 6477 // Update code cache.
6481 static void UpdateCodeCache(Handle<Map> map, 6478 static void UpdateCodeCache(Handle<Map> map,
6482 Handle<Name> name, 6479 Handle<Name> name,
6483 Handle<Code> code); 6480 Handle<Code> code);
6484 MUST_USE_RESULT MaybeObject* UpdateCodeCache(Name* name, Code* code); 6481 MUST_USE_RESULT MaybeObject* UpdateCodeCache(Name* name, Code* code);
(...skipping 2303 matching lines...) Expand 10 before | Expand all | Expand 10 after
8788 inline void set_hash_field(uint32_t value); 8785 inline void set_hash_field(uint32_t value);
8789 8786
8790 // Tells whether the hash code has been computed. 8787 // Tells whether the hash code has been computed.
8791 inline bool HasHashCode(); 8788 inline bool HasHashCode();
8792 8789
8793 // Returns a hash value used for the property table 8790 // Returns a hash value used for the property table
8794 inline uint32_t Hash(); 8791 inline uint32_t Hash();
8795 8792
8796 // Equality operations. 8793 // Equality operations.
8797 inline bool Equals(Name* other); 8794 inline bool Equals(Name* other);
8795 inline static bool Equals(Handle<Name> one, Handle<Name> two);
8798 8796
8799 // Conversion. 8797 // Conversion.
8800 inline bool AsArrayIndex(uint32_t* index); 8798 inline bool AsArrayIndex(uint32_t* index);
8801 8799
8802 // Casting. 8800 // Casting.
8803 static inline Name* cast(Object* obj); 8801 static inline Name* cast(Object* obj);
8804 8802
8805 bool IsCacheable(Isolate* isolate); 8803 bool IsCacheable(Isolate* isolate);
8806 8804
8807 DECLARE_PRINTER(Name) 8805 DECLARE_PRINTER(Name)
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
8924 bool IsFlat() { return state_ != NON_FLAT; } 8922 bool IsFlat() { return state_ != NON_FLAT; }
8925 // Returns true if the structure contains ASCII content. 8923 // Returns true if the structure contains ASCII content.
8926 bool IsAscii() { return state_ == ASCII; } 8924 bool IsAscii() { return state_ == ASCII; }
8927 // Returns true if the structure contains two-byte content. 8925 // Returns true if the structure contains two-byte content.
8928 bool IsTwoByte() { return state_ == TWO_BYTE; } 8926 bool IsTwoByte() { return state_ == TWO_BYTE; }
8929 8927
8930 // Return the one byte content of the string. Only use if IsAscii() returns 8928 // Return the one byte content of the string. Only use if IsAscii() returns
8931 // true. 8929 // true.
8932 Vector<const uint8_t> ToOneByteVector() { 8930 Vector<const uint8_t> ToOneByteVector() {
8933 ASSERT_EQ(ASCII, state_); 8931 ASSERT_EQ(ASCII, state_);
8934 return buffer_; 8932 return Vector<const uint8_t>(onebyte_start, length_);
8935 } 8933 }
8936 // Return the two-byte content of the string. Only use if IsTwoByte() 8934 // Return the two-byte content of the string. Only use if IsTwoByte()
8937 // returns true. 8935 // returns true.
8938 Vector<const uc16> ToUC16Vector() { 8936 Vector<const uc16> ToUC16Vector() {
8939 ASSERT_EQ(TWO_BYTE, state_); 8937 ASSERT_EQ(TWO_BYTE, state_);
8940 return Vector<const uc16>::cast(buffer_); 8938 return Vector<const uc16>(twobyte_start, length_);
8939 }
8940
8941 uc16 Get(int i) {
8942 ASSERT(i < length_);
8943 ASSERT(state_ != NON_FLAT);
8944 if (state_ == ASCII) return onebyte_start[i];
8945 return twobyte_start[i];
8941 } 8946 }
8942 8947
8943 private: 8948 private:
8944 enum State { NON_FLAT, ASCII, TWO_BYTE }; 8949 enum State { NON_FLAT, ASCII, TWO_BYTE };
8945 8950
8946 // Constructors only used by String::GetFlatContent(). 8951 // Constructors only used by String::GetFlatContent().
8947 explicit FlatContent(Vector<const uint8_t> chars) 8952 explicit FlatContent(const uint8_t* start, int length)
8948 : buffer_(chars), 8953 : onebyte_start(start), length_(length), state_(ASCII) { }
8949 state_(ASCII) { } 8954 explicit FlatContent(const uc16* start, int length)
8950 explicit FlatContent(Vector<const uc16> chars) 8955 : twobyte_start(start), length_(length), state_(TWO_BYTE) { }
8951 : buffer_(Vector<const byte>::cast(chars)), 8956 FlatContent() : onebyte_start(NULL), length_(0), state_(NON_FLAT) { }
8952 state_(TWO_BYTE) { }
8953 FlatContent() : buffer_(), state_(NON_FLAT) { }
8954 8957
8955 Vector<const uint8_t> buffer_; 8958 union {
8959 const uint8_t* onebyte_start;
8960 const uc16* twobyte_start;
8961 };
8962 int length_;
8956 State state_; 8963 State state_;
8957 8964
8958 friend class String; 8965 friend class String;
8959 }; 8966 };
8960 8967
8961 // Get and set the length of the string. 8968 // Get and set the length of the string.
8962 inline int length(); 8969 inline int length();
8963 inline void set_length(int value); 8970 inline void set_length(int value);
8964 8971
8965 // Get and set the length of the string using acquire loads and release 8972 // Get and set the length of the string using acquire loads and release
(...skipping 17 matching lines...) Expand all
8983 // NOTE: this should be considered only a hint. False negatives are 8990 // NOTE: this should be considered only a hint. False negatives are
8984 // possible. 8991 // possible.
8985 inline bool HasOnlyOneByteChars(); 8992 inline bool HasOnlyOneByteChars();
8986 8993
8987 // Get and set individual two byte chars in the string. 8994 // Get and set individual two byte chars in the string.
8988 inline void Set(int index, uint16_t value); 8995 inline void Set(int index, uint16_t value);
8989 // Get individual two byte char in the string. Repeated calls 8996 // Get individual two byte char in the string. Repeated calls
8990 // to this method are not efficient unless the string is flat. 8997 // to this method are not efficient unless the string is flat.
8991 INLINE(uint16_t Get(int index)); 8998 INLINE(uint16_t Get(int index));
8992 8999
8993 // Try to flatten the string. Checks first inline to see if it is 9000 // Flattens the string. Checks first inline to see if it is
8994 // necessary. Does nothing if the string is not a cons string. 9001 // necessary. Does nothing if the string is not a cons string.
8995 // Flattening allocates a sequential string with the same data as 9002 // Flattening allocates a sequential string with the same data as
8996 // the given string and mutates the cons string to a degenerate 9003 // the given string and mutates the cons string to a degenerate
8997 // form, where the first component is the new sequential string and 9004 // form, where the first component is the new sequential string and
8998 // the second component is the empty string. If allocation fails, 9005 // the second component is the empty string. If allocation fails,
8999 // this function returns a failure. If flattening succeeds, this 9006 // this function returns a failure. If flattening succeeds, this
9000 // function returns the sequential string that is now the first 9007 // function returns the sequential string that is now the first
9001 // component of the cons string. 9008 // component of the cons string.
9002 // 9009 //
9003 // Degenerate cons strings are handled specially by the garbage 9010 // Degenerate cons strings are handled specially by the garbage
9004 // collector (see IsShortcutCandidate). 9011 // collector (see IsShortcutCandidate).
9005 //
9006 // Use FlattenString from Handles.cc to flatten even in case an
9007 // allocation failure happens.
9008 inline MaybeObject* TryFlatten(PretenureFlag pretenure = NOT_TENURED);
9009
9010 // Convenience function. Has exactly the same behavior as
9011 // TryFlatten(), except in the case of failure returns the original
9012 // string.
9013 inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED);
9014 9012
9015 static inline Handle<String> Flatten(Handle<String> string, 9013 static inline Handle<String> Flatten(Handle<String> string,
9016 PretenureFlag pretenure = NOT_TENURED); 9014 PretenureFlag pretenure = NOT_TENURED);
9017 9015
9018 static Handle<String> SlowFlatten(Handle<ConsString> cons,
9019 PretenureFlag tenure);
9020
9021
9022 // Tries to return the content of a flat string as a structure holding either 9016 // Tries to return the content of a flat string as a structure holding either
9023 // a flat vector of char or of uc16. 9017 // a flat vector of char or of uc16.
9024 // If the string isn't flat, and therefore doesn't have flat content, the 9018 // If the string isn't flat, and therefore doesn't have flat content, the
9025 // returned structure will report so, and can't provide a vector of either 9019 // returned structure will report so, and can't provide a vector of either
9026 // kind. 9020 // kind.
9027 FlatContent GetFlatContent(); 9021 FlatContent GetFlatContent();
9028 9022
9029 // Returns the parent of a sliced string or first part of a flat cons string. 9023 // Returns the parent of a sliced string or first part of a flat cons string.
9030 // Requires: StringShape(this).IsIndirect() && this->IsFlat() 9024 // Requires: StringShape(this).IsIndirect() && this->IsFlat()
9031 inline String* GetUnderlying(); 9025 inline String* GetUnderlying();
9032 9026
9033 // Mark the string as an undetectable object. It only applies to 9027 // Mark the string as an undetectable object. It only applies to
9034 // ASCII and two byte string types. 9028 // ASCII and two byte string types.
9035 bool MarkAsUndetectable(); 9029 bool MarkAsUndetectable();
9036 9030
9037 // String equality operations. 9031 // String equality operations.
9038 inline bool Equals(String* other); 9032 inline bool Equals(String* other);
9033 inline static bool Equals(Handle<String> one, Handle<String> two);
9039 bool IsUtf8EqualTo(Vector<const char> str, bool allow_prefix_match = false); 9034 bool IsUtf8EqualTo(Vector<const char> str, bool allow_prefix_match = false);
9040 bool IsOneByteEqualTo(Vector<const uint8_t> str); 9035 bool IsOneByteEqualTo(Vector<const uint8_t> str);
9041 bool IsTwoByteEqualTo(Vector<const uc16> str); 9036 bool IsTwoByteEqualTo(Vector<const uc16> str);
9042 9037
9043 // Return a UTF8 representation of the string. The string is null 9038 // Return a UTF8 representation of the string. The string is null
9044 // terminated but may optionally contain nulls. Length is returned 9039 // terminated but may optionally contain nulls. Length is returned
9045 // in length_output if length_output is not a null pointer The string 9040 // in length_output if length_output is not a null pointer The string
9046 // should be nearly flat, otherwise the performance of this method may 9041 // should be nearly flat, otherwise the performance of this method may
9047 // be very slow (quadratic in the length). Setting robustness_flag to 9042 // be very slow (quadratic in the length). Setting robustness_flag to
9048 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it 9043 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
9199 static inline ConsString* VisitFlat(Visitor* visitor, 9194 static inline ConsString* VisitFlat(Visitor* visitor,
9200 String* string, 9195 String* string,
9201 int offset = 0) { 9196 int offset = 0) {
9202 int32_t type = string->map()->instance_type(); 9197 int32_t type = string->map()->instance_type();
9203 return VisitFlat(visitor, string, offset, string->length(), type); 9198 return VisitFlat(visitor, string, offset, string->length(), type);
9204 } 9199 }
9205 9200
9206 private: 9201 private:
9207 friend class Name; 9202 friend class Name;
9208 9203
9209 // Try to flatten the top level ConsString that is hiding behind this 9204 static Handle<String> SlowFlatten(Handle<ConsString> cons,
9210 // string. This is a no-op unless the string is a ConsString. Flatten 9205 PretenureFlag tenure);
9211 // mutates the ConsString and might return a failure.
9212 MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure);
9213 9206
9214 // Slow case of String::Equals. This implementation works on any strings 9207 // Slow case of String::Equals. This implementation works on any strings
9215 // but it is most efficient on strings that are almost flat. 9208 // but it is most efficient on strings that are almost flat.
9216 bool SlowEquals(String* other); 9209 bool SlowEquals(String* other);
9217 9210
9211 static bool SlowEquals(Handle<String> one, Handle<String> two);
9212
9218 // Slow case of AsArrayIndex. 9213 // Slow case of AsArrayIndex.
9219 bool SlowAsArrayIndex(uint32_t* index); 9214 bool SlowAsArrayIndex(uint32_t* index);
9220 9215
9221 // Compute and set the hash code. 9216 // Compute and set the hash code.
9222 uint32_t ComputeAndSetHash(); 9217 uint32_t ComputeAndSetHash();
9223 9218
9224 DISALLOW_IMPLICIT_CONSTRUCTORS(String); 9219 DISALLOW_IMPLICIT_CONSTRUCTORS(String);
9225 }; 9220 };
9226 9221
9227 9222
(...skipping 1790 matching lines...) Expand 10 before | Expand all | Expand 10 after
11018 } else { 11013 } else {
11019 value &= ~(1 << bit_position); 11014 value &= ~(1 << bit_position);
11020 } 11015 }
11021 return value; 11016 return value;
11022 } 11017 }
11023 }; 11018 };
11024 11019
11025 } } // namespace v8::internal 11020 } } // namespace v8::internal
11026 11021
11027 #endif // V8_OBJECTS_H_ 11022 #endif // V8_OBJECTS_H_
OLDNEW
« no previous file with comments | « src/mips/lithium-codegen-mips.cc ('k') | src/objects.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698