2828#include " Point.h"
2929#include " util/helpers.h"
3030
31- Point::Point (const String & measurement):
32- _measurement(escapeKey(measurement, false )),
33- _tags(" " ),
34- _fields(" " ),
35- _timestamp(" " )
31+ Point::Point (const String & measurement)
3632{
33+ _measurement = escapeKey (measurement, false );
34+ _timestamp = nullptr ;
35+ }
3736
37+ Point::~Point () {
38+ delete [] _measurement;
39+ delete [] _timestamp;
3840}
3941
4042void Point::addTag (const String &name, String value) {
4143 if (_tags.length () > 0 ) {
4244 _tags += ' ,' ;
4345 }
44- _tags += escapeKey (name);
46+ char *s = escapeKey (name);
47+ _tags += s;
48+ delete [] s;
4549 _tags += ' =' ;
46- _tags += escapeKey (value);
50+ s = escapeKey (value);
51+ _tags += s;
52+ delete [] s;
4753}
4854
4955void Point::addField (const String &name, long long value) {
50- char buff[50 ];
56+ char buff[23 ];
5157 snprintf (buff, 50 , " %lld" , value);
5258 putField (name, String (buff)+" i" );
5359}
5460
5561void Point::addField (const String &name, unsigned long long value) {
56- char buff[50 ];
62+ char buff[23 ];
5763 snprintf (buff, 50 , " %llu" , value);
5864 putField (name, String (buff)+" i" );
5965}
@@ -110,7 +116,9 @@ void Point::putField(const String &name, const String &value) {
110116 if (_fields.length () > 0 ) {
111117 _fields += ' ,' ;
112118 }
113- _fields += escapeKey (name);
119+ char *s = escapeKey (name);
120+ _fields += s;
121+ delete [] s;
114122 _fields += ' =' ;
115123 _fields += value;
116124}
@@ -121,7 +129,7 @@ String Point::toLineProtocol(const String &includeTags) const {
121129
122130String Point::createLineProtocol (const String &incTags) const {
123131 String line;
124- line.reserve (_measurement. length ( ) + 1 + incTags.length () + 1 + _tags.length () + 1 + _fields.length () + 1 + _timestamp. length ( ));
132+ line.reserve (strLen (_measurement ) + 1 + incTags.length () + 1 + _tags.length () + 1 + _fields.length () + 1 + strLen (_timestamp ));
125133 line += _measurement;
126134 if (incTags.length ()>0 ) {
127135 line += " ," ;
@@ -160,22 +168,32 @@ void Point::setTime(WritePrecision precision) {
160168 setTime (getTimeStamp (&tv,0 ));
161169 break ;
162170 case WritePrecision::NoTime:
163- _timestamp = " " ;
171+ setTime (( char *) nullptr ) ;
164172 break ;
165173 }
166174}
167175
168176void Point::setTime (unsigned long long timestamp) {
169- _timestamp = timeStampToString (timestamp);
177+ setTime (timeStampToString (timestamp));
178+ }
179+
180+ void Point::setTime (const String ×tamp) {
181+ setTime (cloneStr (timestamp.c_str ()));
182+ }
183+
184+ void Point::setTime (const char *timestamp) {
185+ setTime (cloneStr (timestamp));
170186}
171187
172- void Point::setTime (const String ×tamp) {
173- _timestamp = timestamp;
188+ void Point::setTime (char *timestamp) {
189+ delete [] _timestamp;
190+ timestamp = timestamp;
174191}
175192
176193void Point::clearFields () {
177194 _fields = (char *)nullptr ;
178- _timestamp = (char *)nullptr ;
195+ delete [] _timestamp;
196+ _timestamp = nullptr ;
179197}
180198
181199void Point:: clearTags() {
0 commit comments