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
90efad4b
Commit
90efad4b
authored
Jan 09, 2009
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The writer now writes less unused blocks, especially for unused DelayedIndexMaps
parent
afabe2a5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
27 deletions
+37
-27
src/util/delayed_index_maps.hpp
src/util/delayed_index_maps.hpp
+6
-1
src/util/io/writer.cpp
src/util/io/writer.cpp
+27
-20
src/util/io/writer.hpp
src/util/io/writer.hpp
+4
-6
No files found.
src/util/delayed_index_maps.hpp
View file @
90efad4b
...
@@ -59,7 +59,12 @@ void Reader::handle(DelayedIndexMapsData<Key,Value>& d) {
...
@@ -59,7 +59,12 @@ void Reader::handle(DelayedIndexMapsData<Key,Value>& d) {
template
<
typename
Key
,
typename
Value
>
template
<
typename
Key
,
typename
Value
>
void
Writer
::
handle
(
const
DelayedIndexMapsData
<
Key
,
Value
>&
d
)
{
void
Writer
::
handle
(
const
DelayedIndexMapsData
<
Key
,
Value
>&
d
)
{
if
(
!
d
.
unread_data
.
empty
())
{
if
(
!
d
.
unread_data
.
empty
())
{
if
(
d
.
unread_data
==
_
(
"
\n
"
))
{
// this is not interesting, it is only used to make unread_data nonempty (see above)
// we don't need to write it
}
else
{
handle
(
d
.
unread_data
);
// TODO: how to handle filenames
handle
(
d
.
unread_data
);
// TODO: how to handle filenames
}
}
else
{
}
else
{
handle
(
d
.
read_data
);
handle
(
d
.
read_data
);
}
}
...
...
src/util/io/writer.cpp
View file @
90efad4b
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
// ----------------------------------------------------------------------------- : Writer
// ----------------------------------------------------------------------------- : Writer
Writer
::
Writer
(
const
OutputStreamP
&
output
,
Version
file_app_version
)
Writer
::
Writer
(
const
OutputStreamP
&
output
,
Version
file_app_version
)
:
indentation
(
0
)
,
just_opened
(
false
)
:
indentation
(
0
)
,
output
(
output
),
stream
(
*
output
)
,
output
(
output
),
stream
(
*
output
)
{
{
stream
.
WriteString
(
BYTE_ORDER_MARK
);
stream
.
WriteString
(
BYTE_ORDER_MARK
);
...
@@ -27,27 +27,35 @@ Writer::Writer(const OutputStreamP& output, Version file_app_version)
...
@@ -27,27 +27,35 @@ Writer::Writer(const OutputStreamP& output, Version file_app_version)
void
Writer
::
enterBlock
(
const
Char
*
name
)
{
void
Writer
::
enterBlock
(
const
Char
*
name
)
{
// indenting into a sub-block?
if
(
just_opened
)
{
writeKey
();
stream
.
WriteString
(
_
(
":
\n
"
));
}
// don't write the key yet
// don't write the key yet
indentation
+=
1
;
pending_opened
.
push_back
(
name
);
opened_key
=
cannocial_name_form
(
name
);
just_opened
=
true
;
}
}
void
Writer
::
exitBlock
()
{
void
Writer
::
exitBlock
()
{
if
(
pending_opened
.
empty
())
{
assert
(
indentation
>
0
);
assert
(
indentation
>
0
);
indentation
-=
1
;
indentation
-=
1
;
just_opened
=
false
;
}
else
{
// this block was apparently empty, ignore it
pending_opened
.
pop_back
();
}
}
}
void
Writer
::
writeKey
()
{
void
Writer
::
writePending
()
{
// In enterBlock we have delayed the actual writing of the keys until this point
// here we write all the pending keys, and increase indentation along the way.
for
(
size_t
i
=
0
;
i
<
pending_opened
.
size
()
;
++
i
)
{
if
(
i
>
0
)
{
// before entering a sub-block, write a colon after the parent's name
stream
.
WriteString
(
_
(
":
\n
"
));
}
indentation
+=
1
;
writeIndentation
();
writeIndentation
();
writeUTF8
(
stream
,
opened_key
);
writeUTF8
(
stream
,
cannocial_name_form
(
pending_opened
[
i
]));
}
pending_opened
.
clear
();
}
}
void
Writer
::
writeIndentation
()
{
void
Writer
::
writeIndentation
()
{
for
(
int
i
=
1
;
i
<
indentation
;
++
i
)
{
for
(
int
i
=
1
;
i
<
indentation
;
++
i
)
{
stream
.
PutChar
(
_
(
'\t'
));
stream
.
PutChar
(
_
(
'\t'
));
...
@@ -57,15 +65,14 @@ void Writer::writeIndentation() {
...
@@ -57,15 +65,14 @@ void Writer::writeIndentation() {
// ----------------------------------------------------------------------------- : Handling basic types
// ----------------------------------------------------------------------------- : Handling basic types
void
Writer
::
handle
(
const
String
&
value
)
{
void
Writer
::
handle
(
const
String
&
value
)
{
if
(
!
just_opened
)
{
if
(
pending_opened
.
empty
()
)
{
throw
InternalError
(
_
(
"Can only write a value in a key that was just opened"
));
throw
InternalError
(
_
(
"Can only write a value in a key that was just opened"
));
}
}
writePending
();
// write indentation and key
// write indentation and key
writeKey
();
writeUTF8
(
stream
,
_
(
": "
));
if
(
value
.
find_first_of
(
_
(
'\n'
))
!=
String
::
npos
||
(
!
value
.
empty
()
&&
isSpace
(
value
.
GetChar
(
0
))))
{
if
(
value
.
find_first_of
(
_
(
'\n'
))
!=
String
::
npos
||
(
!
value
.
empty
()
&&
isSpace
(
value
.
GetChar
(
0
))))
{
// multiline string, or contains leading whitespace
// multiline string, or contains leading whitespace
stream
.
PutChar
(
_
(
'\n'
));
stream
.
WriteString
(
_
(
":
\n
"
));
indentation
+=
1
;
indentation
+=
1
;
// split lines, and write each line
// split lines, and write each line
size_t
start
=
0
,
end
,
size
=
value
.
size
();
size_t
start
=
0
,
end
,
size
=
value
.
size
();
...
@@ -87,10 +94,10 @@ void Writer::handle(const String& value) {
...
@@ -87,10 +94,10 @@ void Writer::handle(const String& value) {
}
}
indentation
-=
1
;
indentation
-=
1
;
}
else
{
}
else
{
stream
.
WriteString
(
_
(
": "
));
writeUTF8
(
stream
,
value
);
writeUTF8
(
stream
,
value
);
}
}
stream
.
PutChar
(
_
(
'\n'
));
stream
.
PutChar
(
_
(
'\n'
));
just_opened
=
false
;
}
}
template
<>
void
Writer
::
handle
(
const
int
&
value
)
{
template
<>
void
Writer
::
handle
(
const
int
&
value
)
{
...
...
src/util/io/writer.hpp
View file @
90efad4b
...
@@ -77,10 +77,8 @@ class Writer {
...
@@ -77,10 +77,8 @@ class Writer {
// --------------------------------------------------- : Data
// --------------------------------------------------- : Data
/// Indentation of the current block
/// Indentation of the current block
int
indentation
;
int
indentation
;
/// Did we just open a block (i.e. not written any lines of it)?
/// Blocks opened to which nothing has been written
bool
just_opened
;
vector
<
const
Char
*>
pending_opened
;
/// Last key opened
String
opened_key
;
/// Output stream we are writing to
/// Output stream we are writing to
OutputStreamP
output
;
OutputStreamP
output
;
...
@@ -94,8 +92,8 @@ class Writer {
...
@@ -94,8 +92,8 @@ class Writer {
/// Leave the block we are in
/// Leave the block we are in
void
exitBlock
();
void
exitBlock
();
/// Write the
opened_key and
the required indentation
/// Write the
pending_opened with
the required indentation
void
write
Key
();
void
write
Pending
();
/// Output some taps to represent the indentation level
/// Output some taps to represent the indentation level
void
writeIndentation
();
void
writeIndentation
();
};
};
...
...
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