Esempio n. 1
0
        /*
        ** resizes the string table
        */
        public static void luaS_resize(lua_State L, int newsize)
        {
            int         i;
            stringtable tb = G(L).strt;

            if (newsize > tb.size)          /* grow table if needed */
            {
                luaM_reallocvector(L, ref tb.hash, tb.size, newsize /*, TString * */);
                for (i = tb.size; i < newsize; i++)
                {
                    tb.hash[i] = null;
                }
            }
            for (i = 0; i < tb.size; i++)      /* rehash */
            {
                TString p = tb.hash[i];
                tb.hash[i] = null;
                while (p != null)                                /* for each node in the list */
                {
                    TString hnext = p.u.hnext;                   /* save next */
                    uint    h     = (uint)lmod(p.hash, newsize); /* new position */
                    p.u.hnext  = tb.hash[h];                     /* chain it */
                    tb.hash[h] = p;
                    p          = hnext;
                }
            }
            if (newsize < tb.size)          /* shrink table if needed */
            /* vanishing slice should be empty */
            {
                lua_assert(tb.hash[newsize] == null && tb.hash[tb.size - 1] == null);
                luaM_reallocvector(L, ref tb.hash, tb.size, newsize /*, TString * */);
            }
            tb.size = newsize;
        }
Esempio n. 2
0
        public static TString newlstr(lua_State L, CharPtr str, uint l,
                                      uint h)
        {
            TString     ts;
            stringtable tb = G(L).strt;

            if (l + 1 > MAX_SIZET / GetUnmanagedSize(typeof(char)))
            {
                luaM_toobig(L);
            }
            if ((tb.nuse > (int)tb.size) && (tb.size <= MAX_INT / 2))
            {
                luaS_resize(L, tb.size * 2);    /* too crowded */
            }
            ts = new TString(new char[l + 1]);
            AddTotalBytes(L, (int)(l + 1) * GetUnmanagedSize(typeof(char)) + GetUnmanagedSize(typeof(TString)));
            ts.tsv.len      = l;
            ts.tsv.hash     = h;
            ts.tsv.marked   = luaC_white(G(L));
            ts.tsv.tt       = LUA_TSTRING;
            ts.tsv.reserved = 0;
            //memcpy(ts+1, str, l*GetUnmanagedSize(typeof(char)));
            memcpy(ts.str.chars, str.chars, str.index, (int)l);
            ts.str[l]   = '\0';       /* ending 0 */
            h           = (uint)lmod(h, tb.size);
            ts.tsv.next = tb.hash[h]; /* chain new entry */
            tb.hash[h]  = obj2gco(ts);
            tb.nuse++;
            return(ts);
        }
Esempio n. 3
0
    /*
    ** resizes the string table
    */
    static void luaS_resize(lua_State L, int newsize)
    {
        int         i;
        stringtable tb = L.l_G.strt;

        if (newsize > tb.size)            /* grow table if needed */
        {
            luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *);
            //for (i = tb->size; i < newsize; i++)
            //	tb->hash[i] = NULL;
        }
        //for (i = 0; i < tb->size; i++) {  /* rehash */
        //	TString* p = tb->hash[i];
        //	tb->hash[i] = NULL;
        //	while (p) {  /* for each node in the list */
        //		TString* hnext = p->u.hnext;  /* save next */
        //		unsigned int h = lmod(p->hash, newsize);  /* new position */
        //		p->u.hnext = tb->hash[h];  /* chain it */
        //		tb->hash[h] = p;
        //		p = hnext;
        //	}
        //}
        //if (newsize < tb->size) {  /* shrink table if needed */
        //						   /* vanishing slice should be empty */
        //	lua_assert(tb->hash[newsize] == NULL && tb->hash[tb->size - 1] == NULL);
        //	luaM_reallocvector(L, tb->hash, tb->size, newsize, TString *);
        //}
        //tb->size = newsize;
    }
Esempio n. 4
0
        public static TString newlstr(lua_State L, CharPtr str, uint l,
                                      uint h)
        {
            uint        totalsize; /* total size of TString object */
            GCObjectRef list;      /* (pointer to) list where it will be inserted */
            TString     ts;
            stringtable tb = G(L).strt;

            if (l + 1 > MAX_SIZET / GetUnmanagedSize(typeof(char)))
            {
                luaM_toobig(L);
            }
            if ((tb.nuse > (int)tb.size) && (tb.size <= MAX_INT / 2))
            {
                luaS_resize(L, tb.size * 2);                                                                          /* too crowded */
            }
            totalsize       = (uint)(GetUnmanagedSize(typeof(TString)) + ((l + 1) * GetUnmanagedSize(typeof(char)))); //FIXME:(uint)
            list            = new ArrayRef(tb.hash, (int)lmod(h, tb.size));                                           //FIXME:(int)
            ts              = luaC_newobj <TString>(L, LUA_TSTRING, totalsize, list, 0).ts;
            ts.tsv.len      = l;
            ts.tsv.hash     = h;
            ts.tsv.reserved = 0;
            //memcpy(ts+1, str, l*GetUnmanagedSize(typeof(char)));
            memcpy(ts.str.chars, str.chars, str.index, (int)l); //FIXME:changed
            ts.str[l] = '\0';                                   /* ending 0 */
            tb.nuse++;
            return(ts);
        }
Esempio n. 5
0
            public Table[] mt;             /* metatables for basic types */

            public global_State()
            {
                strt       = luaM_newobject <stringtable> (null);
                l_registry = luaM_newobject <TValue> (null);
                buff       = luaM_newobject <MBuffer> (null);
                tmname     = luaM_emptyvector <TString> (null, (int)TMS.TM_N);
                mt         = luaM_emptyvector <Table> (null, cc.LUA_NUMTAGS);
            }
Esempio n. 6
0
        public static void luaS_remove(lua_State L, TString ts)
        {
            stringtable tb = G(L).strt;
            TStringRef  p  = new TStringArrayRef(tb.hash, (int)lmod(ts.hash, tb.size));

            while (p.get() != ts)        /* find previous element */
            {
                p = new TStringPtrRef(p.get());
            }
            p.set(p.get().u.hnext);        /* remove element from its list */
            tb.nuse--;
        }
Esempio n. 7
0
        /*
        ** creates a new short string, inserting it into string table
        */
        static TString newshrstr(lua_State L, CharPtr str, uint l,
                                 uint h)
        {
            GCObjectRef list;        /* (pointer to) list where it will be inserted */
            stringtable tb = G(L).strt;
            TString     s;

            if (tb.nuse >= (lu_int32)(tb.size) && tb.size <= MAX_INT / 2)
            {
                luaS_resize(L, tb.size * 2);    /* too crowded */
            }
            list = new ArrayRef(tb.hash, (int)lmod(h, tb.size));
            s    = createstrobj(L, str, l, LUA_TSHRSTR, h, list);
            tb.nuse++;
            return(s);
        }
Esempio n. 8
0
        public static void luaS_remove(lua_State L, TString ts)
        {
            stringtable tb  = G(L).strt;
            long        mod = lmod(ts.hash, tb.size);
            TString     p   = tb.hash[mod];

            if (p == ts)
            {
                tb.hash[mod] = p.hnext;
            }
            else
            {
                TString last = null;
                while (p != ts)    /* find previous element */
                {
                    last = p;
                    p    = p.hnext;
                }
                last.hnext = p.hnext;  /* remove element from its list */
            }
            tb.nuse--;
        }
Esempio n. 9
0
        public static void luaS_resize(lua_State L, int newsize)
        {
            int         i;
            stringtable tb = G(L).strt;

            if (G(L).gcstate == GCSsweepstring)
            {
                return;      /* cannot resize during GC traverse */
            }
            if (newsize > tb.size)
            {
                luaM_reallocvector(L, ref tb.hash, tb.size, newsize /*, GCObject * */);
                for (i = tb.size; i < newsize; i++)
                {
                    tb.hash[i] = null;
                }
            }
            /* rehash */
            for (i = 0; i < tb.size; i++)
            {
                GCObject p = tb.hash[i];
                tb.hash[i] = null;
                while (p != null)                                                           /* for each node in the list */
                {
                    GCObject next = gch(p).next;                                            /* save next */
                    uint     h    = (uint)lmod(gco2ts(p).hash, newsize); /* new position */ //FIXME:(uint)lmod()
                    gch(p).next = tb.hash[h];                                               /* chain it */
                    tb.hash[h]  = p;
                    p           = next;
                }
            }
            if (newsize < tb.size)
            {
                /* shrinking slice must be empty */
                lua_assert(tb.hash[newsize] == null && tb.hash[tb.size - 1] == null);
                luaM_reallocvector(L, ref tb.hash, tb.size, newsize /*, GCObject * */);
            }
            tb.size = newsize;
        }