Commit 666eadb0 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #52 from undingen/performance_improvements

Performance optimizations
parents b8f40b57 e0bfc291
......@@ -105,11 +105,16 @@ Box* _listSlice(BoxedList *self, i64 start, i64 stop, i64 step) {
BoxedList *rtn = new BoxedList();
int cur = start;
while ((step > 0 && cur < stop) || (step < 0 && cur > stop)) {
listAppendInternal(rtn, self->elts->elts[cur]);
cur += step;
if ((step == 1) && ((stop-start) > 0)) {
listAppendArrayInternal(rtn, &self->elts->elts[start], stop-start);
} else {
int cur = start;
while ((step > 0 && cur < stop) || (step < 0 && cur > stop)) {
listAppendInternal(rtn, self->elts->elts[cur]);
cur += step;
}
}
return rtn;
}
......
......@@ -372,10 +372,13 @@ void HCBox::giveAttr(const std::string& attr, Box* val) {
}
void HCBox::setattr(const std::string& attr, Box* val, SetattrRewriteArgs *rewrite_args, SetattrRewriteArgs2 *rewrite_args2) {
RELEASE_ASSERT(attr != "None" || this == builtins_module, "can't assign to None");
static const std::string none_str("None");
static const std::string getattr_str("__getattr__");
static const std::string getattribute_str("__getattribute__");
bool isgetattr = (attr == "__getattr__" || attr == "__getattribute__");
if (isgetattr && this->cls == type_cls) {
RELEASE_ASSERT(attr != none_str || this == builtins_module, "can't assign to None");
if ((this->cls == type_cls) && (attr == getattr_str || attr == getattribute_str)) {
// Will have to embed the clear in the IC, so just disable the patching for now:
rewrite_args = NULL;
rewrite_args2 = NULL;
......
......@@ -246,10 +246,14 @@ extern "C" {
}
extern "C" Box* createSlice(Box* start, Box* stop, Box* step) {
static const std::string start_str("start");
static const std::string stop_str("stop");
static const std::string step_str("step");
BoxedSlice *rtn = new BoxedSlice(start, stop, step);
rtn->setattr("start", start, NULL, NULL);
rtn->setattr("stop", stop, NULL, NULL);
rtn->setattr("step", step, NULL, NULL);
rtn->setattr(start_str, start, NULL, NULL);
rtn->setattr(stop_str, stop, NULL, NULL);
rtn->setattr(step_str, step, NULL, NULL);
return rtn;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment