Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
dd0f3642
Commit
dd0f3642
authored
Sep 21, 2007
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some minor performance tweaks
parent
817b95b6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
9 deletions
+46
-9
src/gfx/color.cpp
src/gfx/color.cpp
+10
-5
src/util/io/reader.cpp
src/util/io/reader.cpp
+36
-4
No files found.
src/gfx/color.cpp
View file @
dd0f3642
...
@@ -62,10 +62,15 @@ void fill_image(Image& image, const Color& color) {
...
@@ -62,10 +62,15 @@ void fill_image(Image& image, const Color& color) {
Byte
*
pos
=
image
.
GetData
();
Byte
*
pos
=
image
.
GetData
();
Byte
*
end
=
pos
+
image
.
GetWidth
()
*
image
.
GetHeight
()
*
3
;
Byte
*
end
=
pos
+
image
.
GetWidth
()
*
image
.
GetHeight
()
*
3
;
Byte
r
=
color
.
Red
(),
g
=
color
.
Green
(),
b
=
color
.
Blue
();
Byte
r
=
color
.
Red
(),
g
=
color
.
Green
(),
b
=
color
.
Blue
();
// fill the image
if
(
r
==
g
&&
r
==
b
)
{
while
(
pos
!=
end
)
{
// optimization: use memset
*
pos
++
=
r
;
memset
(
pos
,
r
,
end
-
pos
);
*
pos
++
=
g
;
}
else
{
*
pos
++
=
b
;
// fill the image
while
(
pos
!=
end
)
{
*
pos
++
=
r
;
*
pos
++
=
g
;
*
pos
++
=
b
;
}
}
}
}
}
src/util/io/reader.cpp
View file @
dd0f3642
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#include <util/vector2d.hpp>
#include <util/vector2d.hpp>
#include <util/error.hpp>
#include <util/error.hpp>
#include <util/io/package_manager.hpp>
#include <util/io/package_manager.hpp>
#undef small
// ----------------------------------------------------------------------------- : Reader
// ----------------------------------------------------------------------------- : Reader
...
@@ -112,12 +113,43 @@ void Reader::moveNext() {
...
@@ -112,12 +113,43 @@ void Reader::moveNext() {
}
}
}
}
/// Faster vector, uses large local storage
/** Usually a line from a file doesn't use very many characters.
* In that case, allocating a vector is a waste of resources.
* 2007-09-21: Profiling => Using this class roughly halves the runtime of read_utf8_line,
* making startup slightly faster.
*/
template
<
typename
T
>
class
LocalVector
{
public:
LocalVector
()
:
size
(
0
),
alloced
(
SMALL_SIZE
),
buffer
(
small
)
{}
~
LocalVector
()
{
if
(
buffer
!=
small
)
free
(
buffer
);
}
void
push_back
(
T
t
)
{
if
(
size
>=
alloced
)
{
// double buffer size
if
(
buffer
!=
small
)
{
buffer
=
(
T
*
)
realloc
(
buffer
,
sizeof
(
T
)
*
alloced
*
2
);
}
else
{
buffer
=
(
T
*
)
malloc
(
sizeof
(
T
)
*
alloced
*
2
);
memcpy
(
buffer
,
small
,
alloced
*
sizeof
(
T
));
}
alloced
*=
2
;
}
buffer
[
size
++
]
=
t
;
}
const
T
*
get
()
{
return
buffer
;
}
private:
static
const
int
SMALL_SIZE
=
1024
;
size_t
size
,
alloced
;
T
*
buffer
;
T
small
[
SMALL_SIZE
];
};
/// Read an UTF-8 encoded line from an input stream
/// Read an UTF-8 encoded line from an input stream
/** As opposed to wx functions, this one actually reports errors
/** As opposed to wx functions, this one actually reports errors
*/
*/
String
read_utf8_line
(
wxInputStream
&
input
,
bool
eat_bom
=
true
,
bool
until_eof
=
false
);
String
read_utf8_line
(
wxInputStream
&
input
,
bool
eat_bom
=
true
,
bool
until_eof
=
false
);
String
read_utf8_line
(
wxInputStream
&
input
,
bool
eat_bom
,
bool
until_eof
)
{
String
read_utf8_line
(
wxInputStream
&
input
,
bool
eat_bom
,
bool
until_eof
)
{
v
ector
<
char
>
buffer
;
LocalV
ector
<
char
>
buffer
;
while
(
!
input
.
Eof
())
{
while
(
!
input
.
Eof
())
{
Byte
c
=
input
.
GetC
();
if
(
input
.
LastRead
()
<=
0
)
break
;
Byte
c
=
input
.
GetC
();
if
(
input
.
LastRead
()
<=
0
)
break
;
if
(
!
until_eof
)
{
if
(
!
until_eof
)
{
...
@@ -135,7 +167,7 @@ String read_utf8_line(wxInputStream& input, bool eat_bom, bool until_eof) {
...
@@ -135,7 +167,7 @@ String read_utf8_line(wxInputStream& input, bool eat_bom, bool until_eof) {
}
}
// convert to string
// convert to string
buffer
.
push_back
(
'\0'
);
buffer
.
push_back
(
'\0'
);
size_t
size
=
wxConvUTF8
.
MB2WC
(
nullptr
,
&
buffer
[
0
]
,
0
);
size_t
size
=
wxConvUTF8
.
MB2WC
(
nullptr
,
buffer
.
get
()
,
0
);
if
(
size
==
-
1
)
{
if
(
size
==
-
1
)
{
throw
ParseError
(
_
(
"Invalid UTF-8 sequence"
));
throw
ParseError
(
_
(
"Invalid UTF-8 sequence"
));
}
else
if
(
size
==
0
)
{
}
else
if
(
size
==
0
)
{
...
@@ -145,13 +177,13 @@ String read_utf8_line(wxInputStream& input, bool eat_bom, bool until_eof) {
...
@@ -145,13 +177,13 @@ String read_utf8_line(wxInputStream& input, bool eat_bom, bool until_eof) {
#ifdef UNICODE
#ifdef UNICODE
// NOTE: wx doc is wrong, parameter to GetWritableChar is numer of characters, not bytes
// NOTE: wx doc is wrong, parameter to GetWritableChar is numer of characters, not bytes
Char
*
result_buf
=
result
.
GetWriteBuf
(
size
+
1
);
Char
*
result_buf
=
result
.
GetWriteBuf
(
size
+
1
);
wxConvUTF8
.
MB2WC
(
result_buf
,
&
buffer
[
0
]
,
size
+
1
);
wxConvUTF8
.
MB2WC
(
result_buf
,
buffer
.
get
()
,
size
+
1
);
result
.
UngetWriteBuf
(
size
);
result
.
UngetWriteBuf
(
size
);
return
eat_bom
?
decodeUTF8BOM
(
result
)
:
result
;
return
eat_bom
?
decodeUTF8BOM
(
result
)
:
result
;
#else
#else
// first to wchar, then back to local
// first to wchar, then back to local
vector
<
wchar_t
>
buf2
;
buf2
.
resize
(
size
+
1
);
vector
<
wchar_t
>
buf2
;
buf2
.
resize
(
size
+
1
);
wxConvUTF8
.
MB2WC
(
&
buf2
[
0
],
&
buffer
[
0
]
,
size
+
1
);
wxConvUTF8
.
MB2WC
(
&
buf2
[
0
],
buffer
.
get
()
,
size
+
1
);
// eat BOM?
// eat BOM?
if
(
eat_bom
&&
buf2
[
0
]
==
0xFEFF
)
{
if
(
eat_bom
&&
buf2
[
0
]
==
0xFEFF
)
{
buf2
.
erase
(
buf2
.
begin
());
// remove BOM
buf2
.
erase
(
buf2
.
begin
());
// remove BOM
...
...
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