Software /
code /
prosody
Comparison
util/pubsub.lua @ 6436:31ca87ea8d46
util.pubsub: One less table allocated per pubsub object created
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 28 Sep 2014 00:05:21 +0200 |
parent | 6435:689cb04ff9fd |
child | 6437:3f1f11dfdf10 |
comparison
equal
deleted
inserted
replaced
6435:689cb04ff9fd | 6436:31ca87ea8d46 |
---|---|
4 module("pubsub", package.seeall); | 4 module("pubsub", package.seeall); |
5 | 5 |
6 local service = {}; | 6 local service = {}; |
7 local service_mt = { __index = service }; | 7 local service_mt = { __index = service }; |
8 | 8 |
9 local default_config = { | 9 local default_config = { __index = { |
10 broadcaster = function () end; | 10 broadcaster = function () end; |
11 get_affiliation = function () end; | 11 get_affiliation = function () end; |
12 capabilities = {}; | 12 capabilities = {}; |
13 }; | 13 } }; |
14 | 14 |
15 function new(config) | 15 function new(config) |
16 config = config or {}; | 16 config = config or {}; |
17 return setmetatable({ | 17 return setmetatable({ |
18 config = setmetatable(config, { __index = default_config }); | 18 config = setmetatable(config, default_config); |
19 affiliations = {}; | 19 affiliations = {}; |
20 subscriptions = {}; | 20 subscriptions = {}; |
21 nodes = {}; | 21 nodes = {}; |
22 data = {}; | 22 data = {}; |
23 events = events.new(); | 23 events = events.new(); |