@@ -93,8 +93,6 @@ struct Impl_CharacterView {
9393 }
9494};
9595
96- // TODO: Explicitly define destructor, copy/move construct/assign operations.
97-
9896// Replacing String with a ReadableString reference for input arguments can make passing of U"" literals faster,
9997// because String is not allowed to assume anything about how long the literal will be available.
10098// Unlike String, it cannot be constructed from a "" literal, because it is not allowed to heap allocate new memory
@@ -106,12 +104,7 @@ class ReadableString {
106104 Handle<DsrChar> characters;
107105 // Pointing to a subset of the buffer or memory that is not shared.
108106 Impl_CharacterView view;
109- // TODO: Merge the pointer and length into a new View type for unified bound checks. Then remove the writer pointer.
110- // SafePointer<const DsrChar> reader;
111- // intptr_t length = 0;
112107public:
113- // TODO: Inline the [] operator for faster reading of characters.
114- // Use the padded read internally, because the old version was hard-coded for buffers padded to default alignment.
115108 // Returning the character by value prevents writing to memory that might be a constant literal or shared with other strings
116109 inline DsrChar operator [] (intptr_t index) const {
117110 return this ->view [index];
@@ -123,8 +116,35 @@ class ReadableString {
123116 ReadableString (const DsrChar *content);
124117 ReadableString (Handle<DsrChar> characters, Impl_CharacterView view)
125118 : characters(characters), view(view) {}
126- // Create from String by sharing the buffer
127- ReadableString (const String& source);
119+ // Destructor.
120+ ~ReadableString () {}
121+ // Copy constructor.
122+ ReadableString (const ReadableString& source)
123+ : characters(source.characters), view(source.view) {}
124+ // Move constructor.
125+ ReadableString (ReadableString &&source) noexcept
126+ : characters(source.characters), view(source.view) {
127+ source.characters = Handle<DsrChar>();
128+ source.view = Impl_CharacterView ();
129+ }
130+ // Copy assignment.
131+ ReadableString& operator = (const ReadableString& source) {
132+ if (this != &source) {
133+ this ->characters = source.characters ;
134+ this ->view = source.view ;
135+ }
136+ return *this ;
137+ };
138+ // Move assignment.
139+ ReadableString& operator = (ReadableString &&source) {
140+ if (this != &source) {
141+ this ->characters = source.characters ;
142+ this ->view = source.view ;
143+ source.characters = Handle<DsrChar>();
144+ source.view = Impl_CharacterView ();
145+ }
146+ return *this ;
147+ }
128148};
129149
130150// A safe and simple string type
@@ -134,15 +154,37 @@ class ReadableString {
134154// Endianness is native
135155// No combined characters allowed, use precomposed instead, so that the strings can guarantee a fixed character size
136156class String : public ReadableString {
137- // IMPL_ACCESS:
138- // TODO: Have a single pointer to the data in ReadableString and let the API be responsible for type safety.
139- // SafePointer<DsrChar> writer;
140157public:
141- // Constructors
158+ // Constructors.
142159 String ();
143160 String (const char * source);
144161 String (const DsrChar* source);
145- String (const ReadableString& source);
162+ // Destructor.
163+ ~String () {}
164+ // Copy constructor.
165+ String (const ReadableString& source) : ReadableString(source) {}
166+ String (const String& source) : ReadableString(source) {}
167+ // Move constructor.
168+ String (ReadableString &&source) noexcept : ReadableString(std::move(source)) {}
169+ String (String &&source) noexcept : ReadableString(std::move(source)) {}
170+ // Copy assignment.
171+ String& operator = (const String& source) {
172+ if (this != &source) {
173+ this ->characters = source.characters ;
174+ this ->view = source.view ;
175+ }
176+ return *this ;
177+ };
178+ // Move assignment.
179+ String& operator = (String &&source) {
180+ if (this != &source) {
181+ this ->characters = source.characters ;
182+ this ->view = source.view ;
183+ source.characters = Handle<DsrChar>();
184+ source.view = Impl_CharacterView ();
185+ }
186+ return *this ;
187+ }
146188};
147189
148190// Used as format tags around numbers passed to string_append or string_combine
0 commit comments