Skip to content

Commit a59373b

Browse files
committed
optimize: removed use of the module() function and use of lua tables and table.concat() for simple one-line Lua string concatenation.
1 parent 7c70fbb commit a59373b

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

lib/resty/upload.lua

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
-- Copyright (C) 2012 Yichun Zhang (agentzh)
1+
-- Copyright (C) Yichun Zhang (agentzh)
22

33

44
local sub = string.sub
55
local req_socket = ngx.req.socket
6-
local insert = table.insert
7-
local concat = table.concat
8-
local len = string.len
96
local null = ngx.null
107
local match = string.match
118
local setmetatable = setmetatable
@@ -15,9 +12,7 @@ local type = type
1512
-- local print = print
1613

1714

18-
module(...)
19-
20-
_VERSION = '0.08'
15+
local _M = { _VERSION = '0.08' }
2116

2217

2318
local MAX_LINE_SIZE = 512
@@ -52,7 +47,7 @@ local function get_boundary()
5247
end
5348

5449

55-
function new(self, chunk_size)
50+
function _M.new(self, chunk_size)
5651
local boundary = get_boundary()
5752

5853
-- print("boundary: ", boundary)
@@ -89,7 +84,7 @@ function new(self, chunk_size)
8984
end
9085

9186

92-
function set_timeout(self, timeout)
87+
function _M.set_timeout(self, timeout)
9388
local sock = self.sock
9489
if not sock then
9590
return nil, "not initialized"
@@ -109,7 +104,7 @@ local function discard_line(self)
109104

110105
local dummy, err = self.read_line(1)
111106
if dummy then
112-
return nil, concat({"line too long: ", line, dummy, "..."}, "")
107+
return nil, "line too long: " .. line .. dummy .. "..."
113108
end
114109

115110
if err then
@@ -184,7 +179,7 @@ local function read_header(self)
184179

185180
local dummy, err = read_line(1)
186181
if dummy then
187-
return nil, nil, concat({"line too long: ", line, dummy, "..."}, "")
182+
return nil, nil, "line too long: " .. line .. dummy .. "..."
188183
end
189184

190185
if err then
@@ -213,7 +208,7 @@ local function eof()
213208
end
214209

215210

216-
function read(self)
211+
function _M.read(self)
217212
local size = self.size
218213

219214
local handler = state_handlers[self.state]
@@ -269,12 +264,4 @@ state_handlers = {
269264
}
270265

271266

272-
local class_mt = {
273-
-- to prevent use of casual module global variables
274-
__newindex = function (table, key, val)
275-
error('attempt to write to undeclared variable "' .. key .. '"')
276-
end
277-
}
278-
279-
setmetatable(_M, class_mt)
280-
267+
return _M

0 commit comments

Comments
 (0)