Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[core] Replace boost iostream with std::{i,s}stream #5417

Merged
merged 1 commit into from
Jun 21, 2016

Conversation

brunoabinader
Copy link
Member

@brunoabinader brunoabinader added the Core The cross-platform C++ core, aka mbgl label Jun 21, 2016
@springmeyer
Copy link
Contributor

👍

@brunoabinader brunoabinader merged commit b06176c into master Jun 21, 2016
@jfirebaugh
Copy link
Contributor

🙇

@jfirebaugh jfirebaugh deleted the brunoabinader-stringstream branch June 21, 2016 16:18
@@ -54,8 +44,8 @@ struct png_struct_guard {
};

PremultipliedImage decodePNG(const uint8_t* data, size_t size) {
source_type source(reinterpret_cast<const char*>(data), size);
input_stream stream(source);
std::istringstream source(std::string(reinterpret_cast<const char*>(data), size));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ creates a new std::string and copies data!

@artemp
Copy link
Contributor

artemp commented Jun 22, 2016

Better solution is to implement custom stream buffer : https://artofcode.wordpress.com/2010/12/12/deriving-from-stdstreambuf/
/cc @brunoabinader @jfirebaugh @springmeyer

@artemp
Copy link
Contributor

artemp commented Jun 22, 2016

@brunoabinader This is what II did in mapnik mapnik/mapnik@2e8c0d3
Note: for tiff_reader to work correctly stream buffer must implement

pos_type seekoff( off_type off, ios_base::seekdir dir,
                     ios_base::openmode which = ios_base::in | ios_base::out );

http://en.cppreference.com/w/cpp/io/basic_streambuf/pubseekoff

/cc @springmeyer @jfirebaugh

@jfirebaugh
Copy link
Contributor

@artemp I was wondering about that, thanks for the links.

@mb12
Copy link

mb12 commented Jun 22, 2016

@artemp and @jfirebaugh Is the concern here that duplicate copy of image data in std::string can cause performance issue? This may not be perceptible to the end user at all esp for Vector maps where this code will kick in only once when loading the sprite. #3048 is more likely to be a performance bottleneck arising due to copying data multiple times (But it has not been measured).

When we switched from Curl to OkHttp for network access, it introduced multiple copies of tile data as it moves across JNI boundary. (Issue #3048).

#3048

@brunoabinader
Copy link
Member Author

Thank you @artemp - I wonder if we could add char_array_buffer on its own header-only library so we could share code and avoid duplication? /cc @jfirebaugh

brunoabinader added a commit that referenced this pull request Jun 30, 2016
Implements a custom std::streambuf to avoid creating temporary
std::string objects and thus optimizing image decode.

Suggested by @artemp in
#5417 (comment).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants