** check whether cached closure in prototype 'p' may be reused, that is, ** whether there is a cached closure with the same upvalues needed by ** new closure to be created. */
| 438 | ** new closure to be created. |
| 439 | */ |
| 440 | static Closure *getcached (Proto *p, UpVal **encup, StkId base) { |
| 441 | Closure *c = p->cache; |
| 442 | if (c != NULL) { /* is there a cached closure? */ |
| 443 | int nup = p->sizeupvalues; |
| 444 | Upvaldesc *uv = p->upvalues; |
| 445 | int i; |
| 446 | for (i = 0; i < nup; i++) { /* check whether it has right upvalues */ |
| 447 | TValue *v = uv[i].instack ? base + uv[i].idx : encup[uv[i].idx]->v; |
| 448 | if (c->l.upvals[i]->v != v) |
| 449 | return NULL; /* wrong upvalue; cannot reuse closure */ |
| 450 | } |
| 451 | } |
| 452 | return c; /* return cached closure (or NULL if no cached closure) */ |
| 453 | } |
| 454 | |
| 455 | |
| 456 | /* |