optimized out a braindead pice of code (wonder who wrote it) +40% speed...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-12-14 23:45:11 +03:00
parent c187f40653
commit fead30ce3d

View File

@ -741,10 +741,11 @@ var TagsPrototype = {
tags = this.normalize(tags instanceof Array ? tags : [tags]) tags = this.normalize(tags instanceof Array ? tags : [tags])
var index = this.__index = this.__index || {} var index = this.__index = this.__index || {}
value.forEach(function(value){ tags
tags .forEach(function(tag){
.forEach(function(tag){ index[tag] = tag in index ?
(index[tag] = index[tag] || new Set()).add(value) }) }) index[tag].unite(value)
: new Set(value) })
return this return this
}, },
@ -753,26 +754,30 @@ var TagsPrototype = {
untag: function(tags, value){ untag: function(tags, value){
var that = this var that = this
var index = this.__index = this.__index || {} var index = this.__index = this.__index || {}
value = value instanceof Array ? value : [value] value = value instanceof Array ? value : [value]
tags = this.normalize(tags instanceof Array ? tags : [tags])
this
.normalize(tags instanceof Array ? tags : [tags])
// resolve/match tags...
.map(function(tag){ .map(function(tag){
return /\*/.test(tag) ? return /\*/.test(tag) ?
// resolve tag patterns... // resolve tag patterns...
that.match(tag) that.match(tag)
: tag }) : tag })
.flat() .flat()
// do the untagging...
.forEach(function(tag){
var s = (index[tag] || new Set()).subtract(value)
value.forEach(function(value){ // remove empty sets...
tags if(s.size == 0){
.forEach(function(tag){ delete index[tag]
var s = index[tag] || new Set()
s.delete(value) // update...
// remove empty sets... } else {
if(s.size == 0){ index[tag] = s
delete index[tag] }
} })
}) })
return this return this
}, },