Skip to content

Commit c7c454f

Browse files
author
Enric Sala
committed
Simplify the build method of the write builder using cellfun
There's no need to check for the happy path, the performance difference is not significant
1 parent 5edf709 commit c7c454f

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

influxdb-client/WriteBuilder.m

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,14 @@
4747

4848
% Build line protocol
4949
function lines = build(obj)
50-
lines = '';
5150
if isempty(obj.Items)
5251
warning('this writer is empty');
53-
elseif isscalar(obj.Items)
54-
item = obj.Items{1};
55-
lines = item.toLine(obj.Precision);
52+
lines = '';
5653
else
57-
for i = 1:length(obj.Items)
58-
item = obj.Items{i};
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);
66-
end
54+
f = @(x) x.toLine(obj.Precision);
55+
items = cellfun(f, obj.Items, 'UniformOutput', false);
56+
nonempty = cellfun(@(x) ~isempty(x), items);
57+
lines = strjoin(items(nonempty), newline);
6758
end
6859
end
6960

0 commit comments

Comments
 (0)