Flutter Engine
The Flutter Engine
Classes | Static Public Member Functions | Static Public Attributes | Friends | List of all members
dart::TwoByteString Class Reference

#include <object.h>

Inheritance diagram for dart::TwoByteString:
dart::AllStatic

Classes

struct  ArrayTraits
 

Static Public Member Functions

static uint16_t CharAt (const String &str, intptr_t index)
 
static uint16_t CharAt (TwoByteStringPtr str, intptr_t index)
 
static void SetCharAt (const String &str, intptr_t index, uint16_t ch)
 
static TwoByteStringPtr EscapeSpecialCharacters (const String &str)
 
static intptr_t data_offset ()
 
static intptr_t UnroundedSize (TwoByteStringPtr str)
 
static intptr_t UnroundedSize (intptr_t len)
 
static intptr_t InstanceSize ()
 
static intptr_t InstanceSize (intptr_t len)
 
static TwoByteStringPtr New (intptr_t len, Heap::Space space)
 
static TwoByteStringPtr New (const uint16_t *characters, intptr_t len, Heap::Space space)
 
static TwoByteStringPtr New (intptr_t utf16_len, const int32_t *characters, intptr_t len, Heap::Space space)
 
static TwoByteStringPtr New (const String &str, Heap::Space space)
 
static TwoByteStringPtr New (const TypedDataBase &other_typed_data, intptr_t other_start_index, intptr_t other_len, Heap::Space space=Heap::kNew)
 
static TwoByteStringPtr Concat (const String &str1, const String &str2, Heap::Space space)
 
static TwoByteStringPtr ConcatAll (const Array &strings, intptr_t start, intptr_t end, intptr_t len, Heap::Space space)
 
static TwoByteStringPtr Transform (int32_t(*mapping)(int32_t ch), const String &str, Heap::Space space)
 
static TwoByteStringPtr null ()
 

Static Public Attributes

static constexpr intptr_t kBytesPerElement = 2
 
static constexpr intptr_t kMaxElements = String::kMaxElements
 
static constexpr intptr_t kMaxNewSpaceElements
 
static const ClassId kClassId = kTwoByteStringCid
 

Friends

class Class
 
class FlowGraphSerializer
 
class ImageWriter
 
class String
 
class StringHasher
 
class Symbols
 
class TwoByteStringMessageSerializationCluster
 
class JSONWriter
 

Detailed Description

Definition at line 10662 of file object.h.

Member Function Documentation

◆ CharAt() [1/2]

static uint16_t dart::TwoByteString::CharAt ( const String str,
intptr_t  index 
)
inlinestatic

Definition at line 10664 of file object.h.

10664 {
10665 ASSERT(str.IsTwoByteString());
10666 return TwoByteString::CharAt(static_cast<TwoByteStringPtr>(str.ptr()),
10667 index);
10668 }
static uint16_t CharAt(const String &str, intptr_t index)
Definition: object.h:10664
#define ASSERT(E)

◆ CharAt() [2/2]

static uint16_t dart::TwoByteString::CharAt ( TwoByteStringPtr  str,
intptr_t  index 
)
inlinestatic

Definition at line 10670 of file object.h.

10670 {
10671 ASSERT(index >= 0 && index < String::LengthOf(str));
10672 return str->untag()->data()[index];
10673 }
static intptr_t LengthOf(StringPtr obj)
Definition: object.h:10211

◆ Concat()

TwoByteStringPtr dart::TwoByteString::Concat ( const String str1,
const String str2,
Heap::Space  space 
)
static

Definition at line 24640 of file object.cc.

24642 {
24643 intptr_t len1 = str1.Length();
24644 intptr_t len2 = str2.Length();
24645 intptr_t len = len1 + len2;
24647 String::Copy(result, 0, str1, 0, len1);
24648 String::Copy(result, len1, str2, 0, len2);
24649 return TwoByteString::raw(result);
24650}
static Object & Handle()
Definition: object.h:407
static void Copy(const String &dst, intptr_t dst_offset, const uint8_t *characters, intptr_t len)
Definition: object.cc:23792
static TwoByteStringPtr New(intptr_t len, Heap::Space space)
Definition: object.cc:24562
friend class String
Definition: object.h:10776
GAsyncResult * result

◆ ConcatAll()

TwoByteStringPtr dart::TwoByteString::ConcatAll ( const Array strings,
intptr_t  start,
intptr_t  end,
intptr_t  len,
Heap::Space  space 
)
static

Definition at line 24652 of file object.cc.

24656 {
24657 ASSERT(!strings.IsNull());
24658 ASSERT(start >= 0);
24659 ASSERT(end <= strings.Length());
24661 String& str = String::Handle();
24662 intptr_t pos = 0;
24663 for (intptr_t i = start; i < end; i++) {
24664 str ^= strings.At(i);
24665 const intptr_t str_len = str.Length();
24666 String::Copy(result, pos, str, 0, str_len);
24667 ASSERT((kMaxElements - pos) >= str_len);
24668 pos += str_len;
24669 }
24670 return TwoByteString::raw(result);
24671}
SkPoint pos
static constexpr intptr_t kMaxElements
Definition: object.h:10684
glong glong end
static float Length(float x, float y)
Definition: SkPoint.cpp:79

◆ data_offset()

static intptr_t dart::TwoByteString::data_offset ( )
inlinestatic

Definition at line 10695 of file object.h.

10695 {
10696 return OFFSET_OF_RETURNED_VALUE(UntaggedTwoByteString, data);
10697 }
static int8_t data[kExtLength]
#define OFFSET_OF_RETURNED_VALUE(type, accessor)
Definition: globals.h:143

◆ EscapeSpecialCharacters()

TwoByteStringPtr dart::TwoByteString::EscapeSpecialCharacters ( const String str)
static

Definition at line 24530 of file object.cc.

24530 {
24531 intptr_t len = str.Length();
24532 if (len > 0) {
24533 intptr_t num_escapes = 0;
24534 for (intptr_t i = 0; i < len; i++) {
24535 num_escapes += EscapeOverhead(CharAt(str, i));
24536 }
24537 const String& dststr =
24539 intptr_t index = 0;
24540 for (intptr_t i = 0; i < len; i++) {
24541 uint16_t ch = CharAt(str, i);
24542 if (IsSpecialCharacter(ch)) {
24543 SetCharAt(dststr, index, '\\');
24544 SetCharAt(dststr, index + 1, SpecialCharacter(ch));
24545 index += 2;
24546 } else if (IsAsciiNonprintable(ch)) {
24547 SetCharAt(dststr, index, '\\');
24548 SetCharAt(dststr, index + 1, 'x');
24549 SetCharAt(dststr, index + 2, GetHexCharacter(ch >> 4));
24550 SetCharAt(dststr, index + 3, GetHexCharacter(ch & 0xF));
24551 index += 4;
24552 } else {
24553 SetCharAt(dststr, index, ch);
24554 index += 1;
24555 }
24556 }
24557 return TwoByteString::raw(dststr);
24558 }
24559 return TwoByteString::New(0, Heap::kNew);
24560}
@ kNew
Definition: heap.h:38
static void SetCharAt(const String &str, intptr_t index, uint16_t ch)
Definition: object.h:10675
static type SpecialCharacter(type value)
Definition: object.cc:530
static int32_t GetHexCharacter(int32_t c)
Definition: object.cc:23896
static int32_t EscapeOverhead(int32_t c)
Definition: object.cc:520
static bool IsSpecialCharacter(type value)
Definition: object.cc:510
static bool IsAsciiNonprintable(int32_t c)
Definition: object.cc:516

◆ InstanceSize() [1/2]

static intptr_t dart::TwoByteString::InstanceSize ( )
inlinestatic

Definition at line 10704 of file object.h.

10704 {
10705 ASSERT(sizeof(UntaggedTwoByteString) ==
10706 OFFSET_OF_RETURNED_VALUE(UntaggedTwoByteString, data));
10707 return 0;
10708 }

◆ InstanceSize() [2/2]

static intptr_t dart::TwoByteString::InstanceSize ( intptr_t  len)
inlinestatic

Definition at line 10709 of file object.h.

10709 {
10710 ASSERT(sizeof(UntaggedTwoByteString) == String::kSizeofRawString);
10711 ASSERT(0 <= len && len <= kMaxElements);
10713 }
static constexpr intptr_t RoundedAllocationSize(intptr_t size)
Definition: object.h:758
static constexpr intptr_t kSizeofRawString
Definition: object.h:10170
static intptr_t UnroundedSize(TwoByteStringPtr str)
Definition: object.h:10698

◆ New() [1/5]

TwoByteStringPtr dart::TwoByteString::New ( const String str,
Heap::Space  space 
)
static

Definition at line 24619 of file object.cc.

24619 {
24620 intptr_t len = str.Length();
24622 String::Copy(result, 0, str, 0, len);
24623 return TwoByteString::raw(result);
24624}

◆ New() [2/5]

TwoByteStringPtr dart::TwoByteString::New ( const TypedDataBase other_typed_data,
intptr_t  other_start_index,
intptr_t  other_len,
Heap::Space  space = Heap::kNew 
)
static

Definition at line 24626 of file object.cc.

24629 {
24630 const String& result = String::Handle(TwoByteString::New(other_len, space));
24631 if (other_len > 0) {
24632 NoSafepointScope no_safepoint;
24633 memmove(TwoByteString::DataStart(result),
24634 other_typed_data.DataAddr(other_start_index),
24635 other_len * sizeof(uint16_t));
24636 }
24637 return TwoByteString::raw(result);
24638}

◆ New() [3/5]

TwoByteStringPtr dart::TwoByteString::New ( const uint16_t *  characters,
intptr_t  len,
Heap::Space  space 
)
static

Definition at line 24582 of file object.cc.

24584 {
24585 ASSERT(array_len > 0);
24586 const String& result = String::Handle(TwoByteString::New(array_len, space));
24587 {
24588 NoSafepointScope no_safepoint;
24589 memmove(reinterpret_cast<void*>(DataStart(result)),
24590 reinterpret_cast<const void*>(utf16_array), (array_len * 2));
24591 }
24592 return TwoByteString::raw(result);
24593}

◆ New() [4/5]

TwoByteStringPtr dart::TwoByteString::New ( intptr_t  len,
Heap::Space  space 
)
static

Definition at line 24562 of file object.cc.

24562 {
24563 ASSERT(IsolateGroup::Current()->object_store()->two_byte_string_class() !=
24564 nullptr);
24565 if (len < 0 || len > kMaxElements) {
24566 // This should be caught before we reach here.
24567 FATAL("Fatal error in TwoByteString::New: invalid len %" Pd "\n", len);
24568 }
24569 auto s = Object::Allocate<TwoByteString>(space, len);
24570 NoSafepointScope no_safepoint;
24571 s->untag()->set_length(Smi::New(len));
24572#if !defined(HASH_IN_OBJECT_HEADER)
24573 s->untag()->set_hash(Smi::New(0));
24574#endif
24576 ASSERT(size <= s->untag()->HeapSize());
24577 memset(reinterpret_cast<void*>(UntaggedObject::ToAddr(s) + size), 0,
24578 s->untag()->HeapSize() - size);
24579 return s;
24580}
static IsolateGroup * Current()
Definition: isolate.h:539
static SmiPtr New(intptr_t value)
Definition: object.h:10006
static uword ToAddr(const UntaggedObject *raw_obj)
Definition: raw_object.h:522
struct MyStruct s
#define FATAL(error)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
#define Pd
Definition: globals.h:408

◆ New() [5/5]

TwoByteStringPtr dart::TwoByteString::New ( intptr_t  utf16_len,
const int32_t *  characters,
intptr_t  len,
Heap::Space  space 
)
static

Definition at line 24595 of file object.cc.

24598 {
24599 ASSERT((array_len > 0) && (utf16_len >= array_len));
24600 const String& result = String::Handle(TwoByteString::New(utf16_len, space));
24601 {
24602 NoSafepointScope no_safepoint;
24603 intptr_t j = 0;
24604 for (intptr_t i = 0; i < array_len; ++i) {
24605 if (Utf::IsSupplementary(utf32_array[i])) {
24606 ASSERT(j < (utf16_len - 1));
24607 Utf16::Encode(utf32_array[i], CharAddr(result, j));
24608 j += 2;
24609 } else {
24610 ASSERT(j < utf16_len);
24611 *CharAddr(result, j) = utf32_array[i];
24612 j += 1;
24613 }
24614 }
24615 }
24616 return TwoByteString::raw(result);
24617}
static void Encode(int32_t codepoint, uint16_t *dst)
Definition: unicode.cc:273
static bool IsSupplementary(int32_t code_point)
Definition: unicode.h:31

◆ null()

static TwoByteStringPtr dart::TwoByteString::null ( )
inlinestatic

Definition at line 10743 of file object.h.

10743 {
10744 return static_cast<TwoByteStringPtr>(Object::null());
10745 }
static ObjectPtr null()
Definition: object.h:433

◆ SetCharAt()

static void dart::TwoByteString::SetCharAt ( const String str,
intptr_t  index,
uint16_t  ch 
)
inlinestatic

Definition at line 10675 of file object.h.

10675 {
10676 NoSafepointScope no_safepoint;
10677 *CharAddr(str, index) = ch;
10678 }

◆ Transform()

TwoByteStringPtr dart::TwoByteString::Transform ( int32_t(*)(int32_t ch)  mapping,
const String str,
Heap::Space  space 
)
static

Definition at line 24673 of file object.cc.

24675 {
24676 ASSERT(!str.IsNull());
24677 intptr_t len = str.Length();
24679 String::CodePointIterator it(str);
24680 intptr_t i = 0;
24681 NoSafepointScope no_safepoint;
24682 while (it.Next()) {
24683 int32_t src = it.Current();
24684 int32_t dst = mapping(src);
24685 ASSERT(dst >= 0 && dst <= 0x10FFFF);
24686 intptr_t len = Utf16::Length(dst);
24687 if (len == 1) {
24688 *CharAddr(result, i) = dst;
24689 } else {
24690 ASSERT(len == 2);
24691 Utf16::Encode(dst, CharAddr(result, i));
24692 }
24693 i += len;
24694 }
24695 return TwoByteString::raw(result);
24696}
static intptr_t Length(int32_t ch)
Definition: unicode.h:118
dst
Definition: cp.py:12

◆ UnroundedSize() [1/2]

static intptr_t dart::TwoByteString::UnroundedSize ( intptr_t  len)
inlinestatic

Definition at line 10701 of file object.h.

10701 {
10702 return sizeof(UntaggedTwoByteString) + (len * kBytesPerElement);
10703 }
static constexpr intptr_t kBytesPerElement
Definition: object.h:10683

◆ UnroundedSize() [2/2]

static intptr_t dart::TwoByteString::UnroundedSize ( TwoByteStringPtr  str)
inlinestatic

Definition at line 10698 of file object.h.

10698 {
10699 return UnroundedSize(Smi::Value(str->untag()->length()));
10700 }
intptr_t Value() const
Definition: object.h:9990

Friends And Related Function Documentation

◆ Class

friend class Class
friend

Definition at line 10773 of file object.h.

◆ FlowGraphSerializer

friend class FlowGraphSerializer
friend

Definition at line 10774 of file object.h.

◆ ImageWriter

friend class ImageWriter
friend

Definition at line 10775 of file object.h.

◆ JSONWriter

friend class JSONWriter
friend

Definition at line 10780 of file object.h.

◆ String

friend class String
friend

Definition at line 10776 of file object.h.

◆ StringHasher

friend class StringHasher
friend

Definition at line 10777 of file object.h.

◆ Symbols

friend class Symbols
friend

Definition at line 10778 of file object.h.

◆ TwoByteStringMessageSerializationCluster

Definition at line 10779 of file object.h.

Member Data Documentation

◆ kBytesPerElement

constexpr intptr_t dart::TwoByteString::kBytesPerElement = 2
staticconstexpr

Definition at line 10683 of file object.h.

◆ kClassId

const ClassId dart::TwoByteString::kClassId = kTwoByteStringCid
static

Definition at line 10747 of file object.h.

◆ kMaxElements

constexpr intptr_t dart::TwoByteString::kMaxElements = String::kMaxElements
staticconstexpr

Definition at line 10684 of file object.h.

◆ kMaxNewSpaceElements

constexpr intptr_t dart::TwoByteString::kMaxNewSpaceElements
staticconstexpr
Initial value:
=
(kNewAllocatableSize - sizeof(UntaggedTwoByteString)) / kBytesPerElement
static constexpr intptr_t kNewAllocatableSize
Definition: spaces.h:54

Definition at line 10685 of file object.h.


The documentation for this class was generated from the following files: