Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce maintenance overhead of the path cache. #1064

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions dev/raphael.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1140,20 +1140,35 @@ define(["eve"], function(eve) {
});
// PATHS
var paths = function (ps) {
// p is the cache
var p = paths.ps = paths.ps || {};
// q is the subset of cache items which have been used this tick
// (and so should not be expired from the cache)
var q = paths.q = paths.q || {};
if (p[ps]) {
p[ps].sleep = 100;
} else {
p[ps] = {
sleep: 100
};
}
setTimeout(function () {
for (var key in p) if (p[has](key) && key != ps) {
p[key].sleep--;
!p[key].sleep && delete p[key];
}
});
// if we've already queued a timeout, just mark this path as being
// used this tick, and increase the amount the lifetime of non-used
// items will be reduced by
if (paths.t) {
q[ps] = 1;
paths.t += 1;
} else {
setTimeout(function () {
for (var key in p) if (p[has](key) && !q[has](key)) {
p[key].sleep -= paths.t;
(p[key].sleep <= 0) && delete p[key];
}
paths.t = 0;
paths.q = {};
});
paths.t = 1;
}
return p[ps];
};
/*\
Expand Down
27 changes: 21 additions & 6 deletions raphael.js
Original file line number Diff line number Diff line change
Expand Up @@ -1215,20 +1215,35 @@ return /******/ (function(modules) { // webpackBootstrap
});
// PATHS
var paths = function (ps) {
// p is the cache
var p = paths.ps = paths.ps || {};
// q is the subset of cache items which have been used this tick
// (and so should not be expired from the cache)
var q = paths.q = paths.q || {};
if (p[ps]) {
p[ps].sleep = 100;
} else {
p[ps] = {
sleep: 100
};
}
setTimeout(function () {
for (var key in p) if (p[has](key) && key != ps) {
p[key].sleep--;
!p[key].sleep && delete p[key];
}
});
// if we've already queued a timeout, just mark this path as being
// used this tick, and increase the amount the lifetime of non-used
// items will be reduced by
if (paths.t) {
q[ps] = 1;
paths.t += 1;
} else {
setTimeout(function () {
for (var key in p) if (p[has](key) && !q[has](key)) {
p[key].sleep -= paths.t;
(p[key].sleep <= 0) && delete p[key];
}
paths.t = 0;
paths.q = {};
});
paths.t = 1;
}
return p[ps];
};
/*\
Expand Down
6 changes: 3 additions & 3 deletions raphael.min.js

Large diffs are not rendered by default.

27 changes: 21 additions & 6 deletions raphael.no-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -1215,20 +1215,35 @@ return /******/ (function(modules) { // webpackBootstrap
});
// PATHS
var paths = function (ps) {
// p is the cache
var p = paths.ps = paths.ps || {};
// q is the subset of cache items which have been used this tick
// (and so should not be expired from the cache)
var q = paths.q = paths.q || {};
if (p[ps]) {
p[ps].sleep = 100;
} else {
p[ps] = {
sleep: 100
};
}
setTimeout(function () {
for (var key in p) if (p[has](key) && key != ps) {
p[key].sleep--;
!p[key].sleep && delete p[key];
}
});
// if we've already queued a timeout, just mark this path as being
// used this tick, and increase the amount the lifetime of non-used
// items will be reduced by
if (paths.t) {
q[ps] = 1;
paths.t += 1;
} else {
setTimeout(function () {
for (var key in p) if (p[has](key) && !q[has](key)) {
p[key].sleep -= paths.t;
(p[key].sleep <= 0) && delete p[key];
}
paths.t = 0;
paths.q = {};
});
paths.t = 1;
}
return p[ps];
};
/*\
Expand Down
6 changes: 3 additions & 3 deletions raphael.no-deps.min.js

Large diffs are not rendered by default.