Commit e51eff87 authored by Kevin Modzelewski's avatar Kevin Modzelewski

There were places we would mutate the result of boxString

Switch those to just calling 'new BoxedString' instead.
parent b6945555
......@@ -1150,7 +1150,7 @@ extern "C" Box* strMul(BoxedString* lhs, Box* rhs) {
else
return NotImplemented;
if (n <= 0)
return boxString("");
return EmptyString;
// TODO: use createUninitializedString and getWriteableStringContents
int sz = lhs->size();
......@@ -1951,7 +1951,7 @@ Box* strTranslate(BoxedString* self, BoxedString* table, BoxedString* delete_cha
Box* strLower(BoxedString* self) {
assert(isSubclass(self->cls, str_cls));
BoxedString* rtn = static_cast<BoxedString*>(boxString(self->s()));
BoxedString* rtn = new (self->size()) BoxedString(self->s());
for (int i = 0; i < rtn->size(); i++)
rtn->data()[i] = std::tolower(rtn->data()[i]);
return rtn;
......@@ -1959,7 +1959,7 @@ Box* strLower(BoxedString* self) {
Box* strUpper(BoxedString* self) {
assert(isSubclass(self->cls, str_cls));
BoxedString* rtn = static_cast<BoxedString*>(boxString(self->s()));
BoxedString* rtn = new (self->size()) BoxedString(self->s());
for (int i = 0; i < rtn->size(); i++)
rtn->data()[i] = std::toupper(rtn->data()[i]);
return rtn;
......@@ -1967,7 +1967,7 @@ Box* strUpper(BoxedString* self) {
Box* strSwapcase(BoxedString* self) {
assert(isSubclass(self->cls, str_cls));
BoxedString* rtn = static_cast<BoxedString*>(boxString(self->s()));
BoxedString* rtn = new (self->size()) BoxedString(self->s());
for (int i = 0; i < rtn->size(); i++) {
char c = rtn->data()[i];
if (std::islower(c))
......@@ -2211,7 +2211,7 @@ extern "C" Box* strGetitem(BoxedString* self, Box* slice) {
}
char c = self->s()[n];
return boxString(llvm::StringRef(&c, 1));
return characters[c & UCHAR_MAX];
} else if (slice->cls == slice_cls) {
BoxedSlice* sslice = static_cast<BoxedSlice*>(slice);
......@@ -2260,7 +2260,7 @@ public:
char c = *self->it;
++self->it;
return boxString(llvm::StringRef(&c, 1));
return characters[c & UCHAR_MAX];
}
};
......@@ -2312,7 +2312,6 @@ extern "C" int PyString_AsStringAndSize(register PyObject* obj, register char**
}
BoxedString* createUninitializedString(ssize_t n) {
// I *think* this should avoid doing any copies, by using move constructors:
return new (n) BoxedString(n, 0);
}
......@@ -2507,7 +2506,7 @@ static PyObject* string_zfill(PyObject* self, PyObject* args) {
// Pyston change:
// s = pad(self, fill, 0, '0');
s = pad((BoxedString*)self, boxInt(width), boxString("0"), JUST_RIGHT);
s = pad((BoxedString*)self, boxInt(width), characters['0' & UCHAR_MAX], JUST_RIGHT);
if (s == NULL)
return NULL;
......@@ -2727,7 +2726,8 @@ void setupStr() {
str_cls->tp_richcompare = str_richcompare;
BoxedString* spaceChar = boxString(" ");
BoxedString* spaceChar = characters[' ' & UCHAR_MAX];
assert(spaceChar);
str_cls->giveAttr("ljust",
new BoxedFunction(boxRTFunction((void*)strLjust, UNKNOWN, 3, 1, false, false), { spaceChar }));
str_cls->giveAttr("rjust",
......
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