Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
e51eff87
Commit
e51eff87
authored
Jun 16, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
There were places we would mutate the result of boxString
Switch those to just calling 'new BoxedString' instead.
parent
b6945555
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
9 deletions
+9
-9
src/runtime/str.cpp
src/runtime/str.cpp
+9
-9
No files found.
src/runtime/str.cpp
View file @
e51eff87
...
@@ -1150,7 +1150,7 @@ extern "C" Box* strMul(BoxedString* lhs, Box* rhs) {
...
@@ -1150,7 +1150,7 @@ extern "C" Box* strMul(BoxedString* lhs, Box* rhs) {
else
else
return
NotImplemented
;
return
NotImplemented
;
if
(
n
<=
0
)
if
(
n
<=
0
)
return
boxString
(
""
)
;
return
EmptyString
;
// TODO: use createUninitializedString and getWriteableStringContents
// TODO: use createUninitializedString and getWriteableStringContents
int
sz
=
lhs
->
size
();
int
sz
=
lhs
->
size
();
...
@@ -1951,7 +1951,7 @@ Box* strTranslate(BoxedString* self, BoxedString* table, BoxedString* delete_cha
...
@@ -1951,7 +1951,7 @@ Box* strTranslate(BoxedString* self, BoxedString* table, BoxedString* delete_cha
Box
*
strLower
(
BoxedString
*
self
)
{
Box
*
strLower
(
BoxedString
*
self
)
{
assert
(
isSubclass
(
self
->
cls
,
str_cls
));
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
++
)
for
(
int
i
=
0
;
i
<
rtn
->
size
();
i
++
)
rtn
->
data
()[
i
]
=
std
::
tolower
(
rtn
->
data
()[
i
]);
rtn
->
data
()[
i
]
=
std
::
tolower
(
rtn
->
data
()[
i
]);
return
rtn
;
return
rtn
;
...
@@ -1959,7 +1959,7 @@ Box* strLower(BoxedString* self) {
...
@@ -1959,7 +1959,7 @@ Box* strLower(BoxedString* self) {
Box
*
strUpper
(
BoxedString
*
self
)
{
Box
*
strUpper
(
BoxedString
*
self
)
{
assert
(
isSubclass
(
self
->
cls
,
str_cls
));
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
++
)
for
(
int
i
=
0
;
i
<
rtn
->
size
();
i
++
)
rtn
->
data
()[
i
]
=
std
::
toupper
(
rtn
->
data
()[
i
]);
rtn
->
data
()[
i
]
=
std
::
toupper
(
rtn
->
data
()[
i
]);
return
rtn
;
return
rtn
;
...
@@ -1967,7 +1967,7 @@ Box* strUpper(BoxedString* self) {
...
@@ -1967,7 +1967,7 @@ Box* strUpper(BoxedString* self) {
Box
*
strSwapcase
(
BoxedString
*
self
)
{
Box
*
strSwapcase
(
BoxedString
*
self
)
{
assert
(
isSubclass
(
self
->
cls
,
str_cls
));
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
++
)
{
for
(
int
i
=
0
;
i
<
rtn
->
size
();
i
++
)
{
char
c
=
rtn
->
data
()[
i
];
char
c
=
rtn
->
data
()[
i
];
if
(
std
::
islower
(
c
))
if
(
std
::
islower
(
c
))
...
@@ -2211,7 +2211,7 @@ extern "C" Box* strGetitem(BoxedString* self, Box* slice) {
...
@@ -2211,7 +2211,7 @@ extern "C" Box* strGetitem(BoxedString* self, Box* slice) {
}
}
char
c
=
self
->
s
()[
n
];
char
c
=
self
->
s
()[
n
];
return
boxString
(
llvm
::
StringRef
(
&
c
,
1
))
;
return
characters
[
c
&
UCHAR_MAX
]
;
}
else
if
(
slice
->
cls
==
slice_cls
)
{
}
else
if
(
slice
->
cls
==
slice_cls
)
{
BoxedSlice
*
sslice
=
static_cast
<
BoxedSlice
*>
(
slice
);
BoxedSlice
*
sslice
=
static_cast
<
BoxedSlice
*>
(
slice
);
...
@@ -2260,7 +2260,7 @@ public:
...
@@ -2260,7 +2260,7 @@ public:
char
c
=
*
self
->
it
;
char
c
=
*
self
->
it
;
++
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**
...
@@ -2312,7 +2312,6 @@ extern "C" int PyString_AsStringAndSize(register PyObject* obj, register char**
}
}
BoxedString
*
createUninitializedString
(
ssize_t
n
)
{
BoxedString
*
createUninitializedString
(
ssize_t
n
)
{
// I *think* this should avoid doing any copies, by using move constructors:
return
new
(
n
)
BoxedString
(
n
,
0
);
return
new
(
n
)
BoxedString
(
n
,
0
);
}
}
...
@@ -2507,7 +2506,7 @@ static PyObject* string_zfill(PyObject* self, PyObject* args) {
...
@@ -2507,7 +2506,7 @@ static PyObject* string_zfill(PyObject* self, PyObject* args) {
// Pyston change:
// Pyston change:
// s = pad(self, fill, 0, '0');
// 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
)
if
(
s
==
NULL
)
return
NULL
;
return
NULL
;
...
@@ -2727,7 +2726,8 @@ void setupStr() {
...
@@ -2727,7 +2726,8 @@ void setupStr() {
str_cls
->
tp_richcompare
=
str_richcompare
;
str_cls
->
tp_richcompare
=
str_richcompare
;
BoxedString
*
spaceChar
=
boxString
(
" "
);
BoxedString
*
spaceChar
=
characters
[
' '
&
UCHAR_MAX
];
assert
(
spaceChar
);
str_cls
->
giveAttr
(
"ljust"
,
str_cls
->
giveAttr
(
"ljust"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
strLjust
,
UNKNOWN
,
3
,
1
,
false
,
false
),
{
spaceChar
}));
new
BoxedFunction
(
boxRTFunction
((
void
*
)
strLjust
,
UNKNOWN
,
3
,
1
,
false
,
false
),
{
spaceChar
}));
str_cls
->
giveAttr
(
"rjust"
,
str_cls
->
giveAttr
(
"rjust"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment