Global Metrics
path: .metrics.nargs.average
old: 0.7
new: 1.4
path: .metrics.nargs.sum
old: 14.0
new: 7.0
path: .metrics.nom.total
old: 20.0
new: 5.0
path: .metrics.nom.functions
old: 20.0
new: 5.0
path: .metrics.halstead.N2
old: 255.0
new: 184.0
path: .metrics.halstead.difficulty
old: 39.84375
new: 24.76923076923077
path: .metrics.halstead.bugs
old: 1.0490905746560086
new: 0.5712030409107883
path: .metrics.halstead.length
old: 660.0
new: 432.0
path: .metrics.halstead.level
old: 0.025098039215686273
new: 0.040372670807453416
path: .metrics.halstead.volume
old: 4431.40204165964
new: 2863.8820598743914
path: .metrics.halstead.estimated_program_length
old: 621.8506523353572
new: 582.5000389496093
path: .metrics.halstead.vocabulary
old: 105.0
new: 99.0
path: .metrics.halstead.N1
old: 405.0
new: 248.0
path: .metrics.halstead.effort
old: 176563.6750973763
new: 70936.15563688877
path: .metrics.halstead.purity_ratio
old: 0.9421979580838744
new: 1.3483797197907623
path: .metrics.halstead.time
old: 9809.093060965351
new: 3940.8975353827095
path: .metrics.halstead.n2
old: 80.0
new: 78.0
path: .metrics.halstead.n1
old: 25.0
new: 21.0
path: .metrics.cyclomatic.sum
old: 49.0
new: 22.0
path: .metrics.cyclomatic.average
old: 1.6333333333333333
new: 3.142857142857143
path: .metrics.loc.cloc
old: 80.0
new: 17.0
path: .metrics.loc.sloc
old: 280.0
new: 130.0
path: .metrics.loc.blank
old: 33.0
new: 17.0
path: .metrics.loc.lloc
old: 55.0
new: 41.0
path: .metrics.loc.ploc
old: 167.0
new: 96.0
path: .metrics.nexits.average
old: 0.9
new: 1.4
path: .metrics.nexits.sum
old: 18.0
new: 7.0
path: .metrics.mi.mi_sei
old: 1.8768356722009116
new: 19.030726252248584
path: .metrics.mi.mi_original
old: 24.78475766383923
new: 45.69428849810956
path: .metrics.mi.mi_visual_studio
old: 14.494010329730544
new: 26.721806139245352
path: .metrics.cognitive.average
old: 1.0
new: 3.8
path: .metrics.cognitive.sum
old: 20.0
new: 19.0
Spaces Data
Minimal test - lines (18, 130)
path: .spaces[0].metrics.cognitive.average
old: 1.0
new: 3.8
path: .spaces[0].metrics.cognitive.sum
old: 20.0
new: 19.0
path: .spaces[0].metrics.halstead.difficulty
old: 40.74675324675325
new: 26.47826086956522
path: .spaces[0].metrics.halstead.effort
old: 178353.06284215234
new: 72366.94450064648
path: .spaces[0].metrics.halstead.level
old: 0.02454183266932271
new: 0.03776683087027914
path: .spaces[0].metrics.halstead.vocabulary
old: 102.0
new: 90.0
path: .spaces[0].metrics.halstead.estimated_program_length
old: 598.6389683778755
new: 513.7268533960477
path: .spaces[0].metrics.halstead.n1
old: 25.0
new: 21.0
path: .spaces[0].metrics.halstead.n2
old: 77.0
new: 69.0
path: .spaces[0].metrics.halstead.volume
old: 4377.1110243333005
new: 2733.0701535547933
path: .spaces[0].metrics.halstead.N2
old: 251.0
new: 174.0
path: .spaces[0].metrics.halstead.bugs
old: 1.0561666742042155
new: 0.5788582615854655
path: .spaces[0].metrics.halstead.N1
old: 405.0
new: 247.0
path: .spaces[0].metrics.halstead.time
old: 9908.503491230686
new: 4020.385805591471
path: .spaces[0].metrics.halstead.purity_ratio
old: 0.912559403015054
new: 1.220253808541681
path: .spaces[0].metrics.halstead.length
old: 656.0
new: 421.0
path: .spaces[0].metrics.nom.functions
old: 20.0
new: 5.0
path: .spaces[0].metrics.nom.total
old: 20.0
new: 5.0
path: .spaces[0].metrics.nargs.average
old: 0.7
new: 1.4
path: .spaces[0].metrics.nargs.sum
old: 14.0
new: 7.0
path: .spaces[0].metrics.mi.mi_visual_studio
old: 15.25938878768836
new: 28.32618531731518
path: .spaces[0].metrics.mi.mi_sei
old: 3.258472024854626
new: 20.501841928902188
path: .spaces[0].metrics.mi.mi_original
old: 26.0935548269471
new: 48.43777689260895
path: .spaces[0].metrics.cyclomatic.average
old: 1.6551724137931034
new: 3.5
path: .spaces[0].metrics.cyclomatic.sum
old: 48.0
new: 21.0
path: .spaces[0].metrics.nexits.average
old: 0.9
new: 1.4
path: .spaces[0].metrics.nexits.sum
old: 18.0
new: 7.0
path: .spaces[0].metrics.loc.blank
old: 29.0
new: 15.0
path: .spaces[0].metrics.loc.ploc
old: 161.0
new: 86.0
path: .spaces[0].metrics.loc.sloc
old: 263.0
new: 113.0
path: .spaces[0].metrics.loc.cloc
old: 73.0
new: 12.0
path: .spaces[0].metrics.loc.lloc
old: 55.0
new: 41.0
Code
namespace mozilla::widget {
NS_IMPL_ISUPPORTS(IconLoader, imgINotificationObserver)
IconLoader::IconLoader(Listener* aListener) : mListener(aListener) {}
IconLoader::~IconLoader() { Destroy(); }
void IconLoader::Destroy() {
if (mIconRequest) {
mIconRequest->CancelAndForgetObserver(NS_BINDING_ABORTED);
mIconRequest = nullptr;
}
mListener = nullptr;
}
nsresult IconLoader::LoadIcon(nsIURI* aIconURI, nsINode* aNode,
bool aIsInternalIcon) {
if (mIconRequest) {
// Another icon request is already in flight. Kill it.
mIconRequest->Cancel(NS_BINDING_ABORTED);
mIconRequest = nullptr;
}
if (!aNode) {
return NS_ERROR_FAILURE;
}
RefPtr document = aNode->OwnerDoc();
nsCOMPtr loadGroup = document->GetDocumentLoadGroup();
if (!loadGroup) {
return NS_ERROR_FAILURE;
}
RefPtr loader = nsContentUtils::GetImgLoaderForDocument(document);
if (!loader) {
return NS_ERROR_FAILURE;
}
nsresult rv;
if (aIsInternalIcon) {
rv = loader->LoadImage(
aIconURI, nullptr, nullptr, nullptr, 0, loadGroup, this, nullptr,
nullptr, nsIRequest::LOAD_NORMAL, nullptr,
nsIContentPolicy::TYPE_INTERNAL_IMAGE, u""_ns,
/* aUseUrgentStartForChannel */ false, /* aLinkPreload */ false,
getter_AddRefs(mIconRequest));
} else {
// TODO: nsIContentPolicy::TYPE_INTERNAL_IMAGE may not be the correct
// policy. See bug 1691868 for more details.
rv = loader->LoadImage(
aIconURI, nullptr, nullptr, aNode->NodePrincipal(), 0, loadGroup, this,
aNode, document, nsIRequest::LOAD_NORMAL, nullptr,
nsIContentPolicy::TYPE_INTERNAL_IMAGE, u""_ns,
/* aUseUrgentStartForChannel */ false,
/* aLinkPreload */ false, getter_AddRefs(mIconRequest));
}
if (NS_FAILED(rv)) {
return rv;
}
return NS_OK;
}
//
// imgINotificationObserver
//
void IconLoader::Notify(imgIRequest* aRequest, int32_t aType,
const nsIntRect* aData) {
if (aType == imgINotificationObserver::LOAD_COMPLETE) {
// Make sure the image loaded successfully.
uint32_t status = imgIRequest::STATUS_ERROR;
if (NS_FAILED(aRequest->GetImageStatus(&status)) ||
(status & imgIRequest::STATUS_ERROR)) {
mIconRequest->Cancel(NS_BINDING_ABORTED);
mIconRequest = nullptr;
return;
}
nsCOMPtr image;
aRequest->GetImage(getter_AddRefs(image));
MOZ_ASSERT(image);
// Ask the image to decode at its intrinsic size.
int32_t width = 0, height = 0;
image->GetWidth(&width);
image->GetHeight(&height);
image->RequestDecodeForSize(nsIntSize(width, height),
imgIContainer::FLAG_HIGH_QUALITY_SCALING);
}
if (aType == imgINotificationObserver::FRAME_COMPLETE) {
nsCOMPtr image;
aRequest->GetImage(getter_AddRefs(image));
MOZ_ASSERT(image);
if (mListener) {
mListener->OnComplete(image);
}
return;
}
if (aType == imgINotificationObserver::DECODE_COMPLETE) {
if (mIconRequest && mIconRequest == aRequest) {
mIconRequest->Cancel(NS_BINDING_ABORTED);
mIconRequest = nullptr;
}
}
}
} // namespace mozilla::widget
Minimal test - lines (22, 22)
path: .spaces[0].spaces[0].metrics.nexits.average
old: 0.9
new: 0.0
path: .spaces[0].spaces[0].metrics.nexits.sum
old: 18.0
new: 0.0
path: .spaces[0].spaces[0].metrics.nom.total
old: 20.0
new: 1.0
path: .spaces[0].spaces[0].metrics.nom.functions
old: 20.0
new: 1.0
path: .spaces[0].spaces[0].metrics.cognitive.sum
old: 20.0
new: 0.0
path: .spaces[0].spaces[0].metrics.cognitive.average
old: 1.0
new: 0.0
path: .spaces[0].spaces[0].metrics.halstead.N1
old: 404.0
new: 6.0
path: .spaces[0].spaces[0].metrics.halstead.volume
old: 4354.470309719673
new: 34.86917501586544
path: .spaces[0].spaces[0].metrics.halstead.level
old: 0.02432
new: 0.32
path: .spaces[0].spaces[0].metrics.halstead.n1
old: 25.0
new: 5.0
path: .spaces[0].spaces[0].metrics.halstead.n2
old: 76.0
new: 4.0
path: .spaces[0].spaces[0].metrics.halstead.purity_ratio
old: 0.9035762932203067
new: 1.7826945885851644
path: .spaces[0].spaces[0].metrics.halstead.time
old: 9947.163536457589
new: 6.053676218032194
path: .spaces[0].spaces[0].metrics.halstead.vocabulary
old: 101.0
new: 9.0
path: .spaces[0].spaces[0].metrics.halstead.estimated_program_length
old: 590.9388957660806
new: 19.60964047443681
path: .spaces[0].spaces[0].metrics.halstead.difficulty
old: 41.11842105263158
new: 3.125
path: .spaces[0].spaces[0].metrics.halstead.effort
old: 179048.94365623657
new: 108.9661719245795
path: .spaces[0].spaces[0].metrics.halstead.length
old: 654.0
new: 11.0
path: .spaces[0].spaces[0].metrics.halstead.bugs
old: 1.0589121237956889
new: 0.007604544540941429
path: .spaces[0].spaces[0].metrics.halstead.N2
old: 250.0
new: 5.0
path: .spaces[0].spaces[0].metrics.mi.mi_visual_studio
old: 15.481980398569773
new: 89.06530020579255
path: .spaces[0].spaces[0].metrics.mi.mi_original
old: 26.474186481554312
new: 152.30166335190526
path: .spaces[0].spaces[0].metrics.mi.mi_sei
old: 3.619709529493512
new: 144.12582230432585
path: .spaces[0].spaces[0].metrics.cyclomatic.average
old: 1.6785714285714286
new: 1.0
path: .spaces[0].spaces[0].metrics.cyclomatic.sum
old: 47.0
new: 1.0
path: .spaces[0].spaces[0].metrics.nargs.average
old: 0.7
new: 1.0
path: .spaces[0].spaces[0].metrics.nargs.sum
old: 14.0
new: 1.0
path: .spaces[0].spaces[0].metrics.loc.sloc
old: 261.0
new: 1.0
path: .spaces[0].spaces[0].metrics.loc.cloc
old: 72.0
new: 0.0
path: .spaces[0].spaces[0].metrics.loc.blank
old: 30.0
new: 0.0
path: .spaces[0].spaces[0].metrics.loc.ploc
old: 159.0
new: 1.0
path: .spaces[0].spaces[0].metrics.loc.lloc
old: 55.0
new: 0.0
Code
IconLoader::IconLoader(Listener* aListener) : mListener(aListener) {}