Software / code / prosody
Comparison
plugins/mod_storage_internal.lua @ 8394:4892c22403d5
mod_storage_internal: Optimize truncation
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 10 Nov 2017 09:44:30 +0100 |
| parent | 8393:b6a7b83f8d87 |
| child | 8402:469afa02947b |
comparison
equal
deleted
inserted
replaced
| 8393:b6a7b83f8d87 | 8394:4892c22403d5 |
|---|---|
| 193 end | 193 end |
| 194 if query.truncate then | 194 if query.truncate then |
| 195 if query.reverse then | 195 if query.reverse then |
| 196 -- Before: { 1, 2, 3, 4, 5, } | 196 -- Before: { 1, 2, 3, 4, 5, } |
| 197 -- After: { 1, 2, 3 } | 197 -- After: { 1, 2, 3 } |
| 198 while #items > query.truncate do | 198 for i = #items, query.truncate + 1, -1 do |
| 199 table.remove(items); | 199 items[i] = nil; |
| 200 end | 200 end |
| 201 else | 201 else |
| 202 -- Before: { 1, 2, 3, 4, 5, } | 202 -- Before: { 1, 2, 3, 4, 5, } |
| 203 -- After: { 3, 4, 5 } | 203 -- After: { 3, 4, 5 } |
| 204 while #items > query.truncate do | 204 local offset = #items - query.truncate; |
| 205 table.remove(items, 1); | 205 for i = 1, #items do |
| 206 items[i] = items[i+offset]; | |
| 206 end | 207 end |
| 207 end | 208 end |
| 208 end | 209 end |
| 209 end | 210 end |
| 210 local count = count_before - #items; | 211 local count = count_before - #items; |