Skip to content

Commit 21deff6

Browse files
fangqclaude
andcommitted
[style] miss_hit formatting of the fast-path readers and writers
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1470b9f commit 21deff6

6 files changed

Lines changed: 102 additions & 104 deletions

File tree

‎jdatadecode.m‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,6 @@
10651065
tf = ~isempty(v) && (islogical(v) || isnumeric(v)) && logical(v(1));
10661066
end
10671067

1068-
10691068
%% -------------------------------------------------------------------------
10701069
function tab = jdatatable_(cols, raw, opt)
10711070
% a decoded _TableData_ as a MATLAB table: a struct of columns (a 1-D column, decoded as a

‎loadbj.m‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@
12511251
arrval = cellfun(@double, elems);
12521252
end
12531253
elseif all(cellfun(@(x) (isnumeric(x) || islogical(x)) && isrow(x) && isequal(size(x), size(elems{1})) && ...
1254-
strcmp(class(x), class(elems{1})), elems))
1254+
strcmp(class(x), class(elems{1})), elems))
12551255
arrval = vertcat(elems{:});
12561256
else
12571257
arrval = elems;

‎loadjson.m‎

Lines changed: 99 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -278,110 +278,110 @@
278278
end
279279
end
280280
if (~fastok)
281-
inputlen = length(jsonstring);
282-
inputstr = jsonstring;
283-
284-
% OPTIMIZATION: Precompute next non-whitespace position lookup table
285-
ws = (inputstr == ' ' | inputstr == char(9) | inputstr == char(10) | inputstr == char(13));
286-
nonws_idx = find(~ws);
287-
if ~isempty(nonws_idx)
288-
marker = repmat(inputlen + 1, 1, inputlen);
289-
marker(nonws_idx) = nonws_idx;
290-
if (exist('cummin', 'builtin'))
291-
cummin_ = @cummin;
281+
inputlen = length(jsonstring);
282+
inputstr = jsonstring;
283+
284+
% OPTIMIZATION: Precompute next non-whitespace position lookup table
285+
ws = (inputstr == ' ' | inputstr == char(9) | inputstr == char(10) | inputstr == char(13));
286+
nonws_idx = find(~ws);
287+
if ~isempty(nonws_idx)
288+
marker = repmat(inputlen + 1, 1, inputlen);
289+
marker(nonws_idx) = nonws_idx;
290+
if (exist('cummin', 'builtin'))
291+
cummin_ = @cummin;
292+
else
293+
cummin_ = @(x) arrayfun(@(i) min(x(1:i)), 1:length(x));
294+
end
295+
opt.next_nonws_ = fliplr(cummin_(fliplr(marker)));
292296
else
293-
cummin_ = @(x) arrayfun(@(i) min(x(1:i)), 1:length(x));
297+
opt.next_nonws_ = repmat(inputlen + 1, 1, inputlen);
298+
end
299+
opt.inputlen_ = inputlen;
300+
opt.utf8bytes_ = exist('OCTAVE_VERSION', 'builtin') ~= 0; % Octave's char holds UTF-8 bytes
301+
302+
% Precompute array tokens for fast array parsing
303+
arraytokenidx = find(inputstr == '[' | inputstr == ']');
304+
arraytoken = inputstr(arraytokenidx);
305+
306+
% String delimiters and escape chars identified to improve speed:
307+
esc = find(inputstr == '"' | inputstr == '\');
308+
309+
opt.arraytoken_ = arraytoken;
310+
opt.arraytokenidx_ = arraytokenidx;
311+
opt.simplifycell = jsonopt('SimplifyCell', 1, opt);
312+
opt.simplifycellarray = jsonopt('SimplifyCellArray', opt.simplifycell, opt);
313+
opt.formatversion = jsonopt('FormatVersion', 3, opt);
314+
opt.fastarrayparser = jsonopt('FastArrayParser', 1, opt);
315+
opt.parsestringarray = jsonopt('ParseStringArray', 0, opt);
316+
opt.usemap = jsonopt('UseMap', 0, opt);
317+
opt.arraydepth_ = 1;
318+
opt.mmaponly = jsonopt('MmapOnly', 0, opt);
319+
320+
if (jsonopt('ShowProgress', 0, opt) == 1)
321+
opt.progressbar_ = waitbar(0, 'loading ...');
294322
end
295-
opt.next_nonws_ = fliplr(cummin_(fliplr(marker)));
296-
else
297-
opt.next_nonws_ = repmat(inputlen + 1, 1, inputlen);
298-
end
299-
opt.inputlen_ = inputlen;
300-
opt.utf8bytes_ = exist('OCTAVE_VERSION', 'builtin') ~= 0; % Octave's char holds UTF-8 bytes
301-
302-
% Precompute array tokens for fast array parsing
303-
arraytokenidx = find(inputstr == '[' | inputstr == ']');
304-
arraytoken = inputstr(arraytokenidx);
305-
306-
% String delimiters and escape chars identified to improve speed:
307-
esc = find(inputstr == '"' | inputstr == '\');
308-
309-
opt.arraytoken_ = arraytoken;
310-
opt.arraytokenidx_ = arraytokenidx;
311-
opt.simplifycell = jsonopt('SimplifyCell', 1, opt);
312-
opt.simplifycellarray = jsonopt('SimplifyCellArray', opt.simplifycell, opt);
313-
opt.formatversion = jsonopt('FormatVersion', 3, opt);
314-
opt.fastarrayparser = jsonopt('FastArrayParser', 1, opt);
315-
opt.parsestringarray = jsonopt('ParseStringArray', 0, opt);
316-
opt.usemap = jsonopt('UseMap', 0, opt);
317-
opt.arraydepth_ = 1;
318-
opt.mmaponly = jsonopt('MmapOnly', 0, opt);
319-
320-
if (jsonopt('ShowProgress', 0, opt) == 1)
321-
opt.progressbar_ = waitbar(0, 'loading ...');
322-
end
323323

324-
objid = jsonopt('ObjectID', 0, opt);
325-
maxobjid = max(objid);
326-
if (maxobjid == 0)
327-
maxobjid = inf;
328-
end
329-
opt.jsonpath_ = '$';
330-
needmmap = (nargout > 1 || opt.mmaponly);
331-
if needmmap
332-
mmap = {};
333-
end
334-
if isempty(nonws_idx)
335-
data = [];
336-
inputlen = 0;
337-
end
324+
objid = jsonopt('ObjectID', 0, opt);
325+
maxobjid = max(objid);
326+
if (maxobjid == 0)
327+
maxobjid = inf;
328+
end
329+
opt.jsonpath_ = '$';
330+
needmmap = (nargout > 1 || opt.mmaponly);
331+
if needmmap
332+
mmap = {};
333+
end
334+
if isempty(nonws_idx)
335+
data = [];
336+
inputlen = 0;
337+
end
338338

339-
jsoncount = 1;
340-
pos = 1;
341-
index_esc = 1;
342-
next_nonws = opt.next_nonws_;
339+
jsoncount = 1;
340+
pos = 1;
341+
index_esc = 1;
342+
next_nonws = opt.next_nonws_;
343343

344-
while pos <= inputlen
345-
% Inline next_char
346-
pos = next_nonws(pos);
347-
cc = inputstr(pos);
344+
while pos <= inputlen
345+
% Inline next_char
346+
pos = next_nonws(pos);
347+
cc = inputstr(pos);
348348

349-
switch cc
350-
case '{'
351-
if needmmap
352-
mmap{end + 1} = {opt.jsonpath_, [pos, 0, mmap_before(inputstr, pos)]};
353-
[data{jsoncount}, pos, index_esc, newmmap] = parse_object(inputstr, pos, esc, index_esc, opt);
354-
if (pos < 0)
355-
opt.usemap = 1;
356-
[data{jsoncount}, pos, index_esc, newmmap] = parse_object(inputstr, -pos, esc, index_esc, opt);
349+
switch cc
350+
case '{'
351+
if needmmap
352+
mmap{end + 1} = {opt.jsonpath_, [pos, 0, mmap_before(inputstr, pos)]};
353+
[data{jsoncount}, pos, index_esc, newmmap] = parse_object(inputstr, pos, esc, index_esc, opt);
354+
if (pos < 0)
355+
opt.usemap = 1;
356+
[data{jsoncount}, pos, index_esc, newmmap] = parse_object(inputstr, -pos, esc, index_esc, opt);
357+
end
358+
mmap{end}{2}(2) = mmap_length(inputstr, mmap{end}{2}(1), pos);
359+
mmap = [mmap(:); newmmap(:)];
360+
else
361+
[data{jsoncount}, pos, index_esc] = parse_object(inputstr, pos, esc, index_esc, opt);
362+
if (pos < 0)
363+
opt.usemap = 1;
364+
[data{jsoncount}, pos, index_esc] = parse_object(inputstr, -pos, esc, index_esc, opt);
365+
end
357366
end
358-
mmap{end}{2}(2) = mmap_length(inputstr, mmap{end}{2}(1), pos);
359-
mmap = [mmap(:); newmmap(:)];
360-
else
361-
[data{jsoncount}, pos, index_esc] = parse_object(inputstr, pos, esc, index_esc, opt);
362-
if (pos < 0)
363-
opt.usemap = 1;
364-
[data{jsoncount}, pos, index_esc] = parse_object(inputstr, -pos, esc, index_esc, opt);
367+
case '['
368+
if needmmap
369+
mmap{end + 1} = {opt.jsonpath_, [pos, 0, mmap_before(inputstr, pos)]};
370+
[data{jsoncount}, pos, index_esc, newmmap] = parse_array(inputstr, pos, esc, index_esc, opt);
371+
mmap{end}{2}(2) = mmap_length(inputstr, mmap{end}{2}(1), pos);
372+
mmap = [mmap(:); newmmap(:)];
373+
else
374+
[data{jsoncount}, pos, index_esc] = parse_array(inputstr, pos, esc, index_esc, opt);
365375
end
366-
end
367-
case '['
368-
if needmmap
369-
mmap{end + 1} = {opt.jsonpath_, [pos, 0, mmap_before(inputstr, pos)]};
370-
[data{jsoncount}, pos, index_esc, newmmap] = parse_array(inputstr, pos, esc, index_esc, opt);
371-
mmap{end}{2}(2) = mmap_length(inputstr, mmap{end}{2}(1), pos);
372-
mmap = [mmap(:); newmmap(:)];
373-
else
374-
[data{jsoncount}, pos, index_esc] = parse_array(inputstr, pos, esc, index_esc, opt);
375-
end
376-
otherwise
377-
error_pos('Outer level structure must be an object or an array', inputstr, pos);
378-
end
379-
if jsoncount >= maxobjid
380-
break
376+
otherwise
377+
error_pos('Outer level structure must be an object or an array', inputstr, pos);
378+
end
379+
if jsoncount >= maxobjid
380+
break
381+
end
382+
opt.jsonpath_ = sprintf('$%d', jsoncount);
383+
jsoncount = jsoncount + 1;
381384
end
382-
opt.jsonpath_ = sprintf('$%d', jsoncount);
383-
jsoncount = jsoncount + 1;
384-
end
385385

386386
end
387387

@@ -1546,10 +1546,10 @@
15461546
dopt = jdopt_(opt, tt, parent, vt, off, nchild, fnt, usemap, isopen);
15471547
end
15481548
try
1549-
V{c} = jdatadecode(V{c}, dopt);
1550-
catch
1551-
return % the element-by-element parser, and its warning
1552-
end
1549+
V{c} = jdatadecode(V{c}, dopt);
1550+
catch
1551+
return % the element-by-element parser, and its warning
1552+
end
15531553
end
15541554
continue
15551555
end

‎loadyaml.m‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
opt.unpackhex = jsonopt('UnpackHex', 1, opt);
9595
opt.fastarrayparser = jsonopt('FastArrayParser', 1, opt);
9696

97-
9897
if (~ischar(yamlstr))
9998
yamlstr = char(yamlstr);
10099
end

‎savebj.m‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2120,7 +2120,7 @@
21202120
if (~isempty(j))
21212121
len = np(j);
21222122
ok = len < 256 & len < opt.compressstringsize & (cellfun('size', c(j), 1) == 1 | ...
2123-
(len == 0 & cellfun('ndims', c(j)) == 2 & cellfun('size', c(j), 1) == 0 & cellfun('size', c(j), 2) == 0));
2123+
(len == 0 & cellfun('ndims', c(j)) == 2 & cellfun('size', c(j), 1) == 0 & cellfun('size', c(j), 2) == 0));
21242124
if (~opt.isoctave && any(ok))
21252125
k = j(ok);
21262126
g = [c{k}];

‎saveyaml.m‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@
969969
w = ismember(lw, {'true', 'false', 'null', 'yes', 'no', 'on', 'off'});
970970
f1 = f1(k);
971971
num = ismember(f1, '0123456789+-.iInN') & (ismember(lw, {'.inf', '.nan', 'inf', 'nan', '-.inf', '+.inf', '-inf', '+inf'}) | ...
972-
~cellfun('isempty', regexp(items(k), '^[+-]?((\d+\.?\d*|\d*\.\d+)([eE][+-]?\d+)?|0[xX][0-9a-fA-F]+)$', 'once')));
972+
~cellfun('isempty', regexp(items(k), '^[+-]?((\d+\.?\d*|\d*\.\d+)([eE][+-]?\d+)?|0[xX][0-9a-fA-F]+)$', 'once')));
973973
q(k) = w | num;
974974
end
975975
q = q & len > 0;

0 commit comments

Comments
 (0)