This is a static copy of a profile report

Home

makeUniqueStrings>makeUnique (Calls: 8, Time: 0.006 s)
Generated 16-Jul-2020 17:09:55 using performance time.
subfunction in file /Applications/MATLAB_R2020a.app/toolbox/matlab/lang/+matlab/+lang/makeUniqueStrings.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
makeUniqueStringsfunction8
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
162
isDuplicateOfPrevious = [false...
80.001 s17.5%
173
isProtectedStart(~isDuplicateO...
80.001 s10.6%
202
uniquified = reshape(uniquifie...
80.001 s9.8%
177
for changeIdx = find(isDuplica...
80.001 s9.3%
163
isDuplicateOfPreviousDiff = di...
80.000 s6.8%
All other lines  0.003 s46.0%
Totals  0.006 s100% 
Children (called functions)
No children
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function51
Non-code lines (comments, blank lines)13
Code lines (lines that can run)38
Code lines that did run19
Code lines that did not run19
Coverage (did run/can run)50.00 %
Function listing
time 
Calls 
 line
 153 
function [str, uniquified] = makeUnique(str, stringsToProtect, maxStringLength)
< 0.001 
      8 
 154
szStrings = size(str); 
< 0.001 
      8 
 155
numStrings = numel(str); 
< 0.001 
      8 
 156
uniquified = false(1, numStrings); 
< 0.001 
      8 
 157
[str, sortIdx] = sort(reshape(str, 1, [])); 
< 0.001 
      8 
 158
stringsToProtect = reshape(stringsToProtect, 1, []); 
 159 

 160 
% Find where there are groups of duplicates by comparing two sorted strings
 161 
% having a one-element shift.
  0.001 
      8 
 162
isDuplicateOfPrevious = [false(min(1, numStrings)), strcmp(str(1:end-1), str(2:end))]; 
< 0.001 
      8 
 163
isDuplicateOfPreviousDiff = diff([isDuplicateOfPrevious, false]); 
< 0.001 
      8 
 164
isDuplicateStart = (isDuplicateOfPreviousDiff > 0); 
< 0.001 
      8 
 165
isDuplicateStopIdx = find(isDuplicateOfPreviousDiff < 0); 
 166 

 167 
% Find where groups of protected strings start.
 168 
% For performance, only call ismember when there are both elements in
 169 
% stringsToProtect and duplicates to compare. This is important for the
 170 
% case when maxStringLength is needed but the second input is {}.
< 0.001 
      8 
 171
isProtectedStart = false(1, numStrings); 
< 0.001 
      8 
 172
if ~isempty(stringsToProtect) && any(~isDuplicateOfPrevious) 
< 0.001 
      8 
 173
    isProtectedStart(~isDuplicateOfPrevious) = matches(str(~isDuplicateOfPrevious), stringsToProtect); 
< 0.001 
      8 
 174
end 
 175 

< 0.001 
      8 
 176
duplicateNum = 1; 
< 0.001 
      8 
 177
for changeIdx = find(isDuplicateStart | isProtectedStart) 
 178 
    if isDuplicateStart(changeIdx) && isProtectedStart(changeIdx)
 179 
        startIdx = changeIdx;
 180 
        stopIdx = isDuplicateStopIdx(duplicateNum);
 181 
        duplicateNum = duplicateNum + 1;
 182 
    elseif isDuplicateStart(changeIdx)
 183 
        startIdx = changeIdx + 1;
 184 
        stopIdx = isDuplicateStopIdx(duplicateNum);
 185 
        duplicateNum = duplicateNum + 1;
 186 
    else % isProtectedStartIdx(changeIdx)
 187 
        startIdx = changeIdx;
 188 
        stopIdx = changeIdx;
 189 
    end
 190 
    try
 191 
        str(startIdx:stopIdx) = makeNameUnique(str, startIdx, stopIdx, stringsToProtect, maxStringLength);
 192 
    catch ex
 193 
        throwAsCaller(ex);
 194 
    end
 195 
    uniquified(startIdx:stopIdx) = true;
 196 
end
 197 

 198 
% Unsort and reshape the now unique STRINGS and MODIFIED to match how
 199 
% STRINGS was input.
< 0.001 
      8 
 200
inverseSortIdx(sortIdx) = 1:numStrings; 
< 0.001 
      8 
 201
str = reshape(str(inverseSortIdx), szStrings); 
< 0.001 
      8 
 202
uniquified = reshape(uniquified(inverseSortIdx), szStrings); 
< 0.001 
      8 
 203
end 

Other subfunctions in this file are not included in this listing.