Skip to content

Commit 5edf709

Browse files
author
Enric Sala
committed
Cleanup and improve the performance of the write builder
Remove the Java StringBuilder, it is not efficient in Matlab
1 parent 0a850e1 commit 5edf709

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

influxdb-client/WriteBuilder.m

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,24 @@
4646
end
4747

4848
% Build line protocol
49-
function str = build(obj)
49+
function lines = build(obj)
50+
lines = '';
5051
if isempty(obj.Items)
5152
warning('this writer is empty');
52-
str = '';
5353
elseif isscalar(obj.Items)
5454
item = obj.Items{1};
55-
str = item.toLine();
55+
lines = item.toLine(obj.Precision);
5656
else
57-
builder = java.lang.StringBuilder();
5857
for i = 1:length(obj.Items)
5958
item = obj.Items{i};
60-
builder.append(item.toLine(obj.Precision));
61-
builder.append(newline);
59+
line = item.toLine(obj.Precision);
60+
if ~isempty(line)
61+
lines = [lines, line, newline];
62+
end
63+
end
64+
if ~isempty(lines)
65+
lines = lines(1:end - 1);
6266
end
63-
builder.deleteCharAt(int32(builder.length() - 1));
64-
str = char(builder.toString());
6567
end
6668
end
6769

0 commit comments

Comments
 (0)