Welcome to mirror list, hosted at ThFree Co, Russian Federation.

zone.lua « jit « src - github.com/torch/luajit-rocks.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fa702c4e989089f9ef5ae078463b09c0a74091de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
----------------------------------------------------------------------------
-- LuaJIT profiler zones.
--
-- Copyright (C) 2005-2017 Mike Pall. All rights reserved.
-- Released under the MIT license. See Copyright Notice in luajit.h
----------------------------------------------------------------------------
--
-- This module implements a simple hierarchical zone model.
--
-- Example usage:
--
--   local zone = require("jit.zone")
--   zone("AI")
--   ...
--     zone("A*")
--     ...
--     print(zone:get()) --> "A*"
--     ...
--     zone()
--   ...
--   print(zone:get()) --> "AI"
--   ...
--   zone()
--
----------------------------------------------------------------------------

local remove = table.remove

return setmetatable({
  flush = function(t)
    for i=#t,1,-1 do t[i] = nil end
  end,
  get = function(t)
    return t[#t]
  end
}, {
  __call = function(t, zone)
    if zone then
      t[#t+1] = zone
    else
      return (assert(remove(t), "empty zone stack"))
    end
  end
})