Skip to content

GEODE-3288: Converts char* to std::string on public API.#160

Merged
jake-at-work merged 3 commits into
apache:developfrom
jake-at-work:feature/GEODE-3288
Dec 2, 2017
Merged

GEODE-3288: Converts char* to std::string on public API.#160
jake-at-work merged 3 commits into
apache:developfrom
jake-at-work:feature/GEODE-3288

Conversation

@jake-at-work

Copy link
Copy Markdown
Contributor

Excludes DataInput/Output, Serializer and CacheableString.

@jake-at-work jake-at-work force-pushed the feature/GEODE-3288 branch 2 times, most recently from 9658b9f to edf10d0 Compare November 29, 2017 03:30
}

string locatorArgs = LocatorStartArgs + " --name=" + serverName + startDir + extraLocatorArgs;
string locatorArgs = LocatorStartArgs + " --name=" + serverName + startDir + extraLocatorArgs + " --http-service-port=0";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This change shaves about 10s off each test!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Very cool!

)

include(PrecompiledHeader)
add_precompiled_header(${PROJECT_NAME} geode_includes.hpp FORCEINCLUDE)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added precompiled headers to work around and speed up issue including marshal_as headers.

@dgkimura dgkimura left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. Just small comments so feel free to ignore as you see fit. I did notice you changed many types to universal refs auto&&, which I assume was intentional. How did you decide on using auto& vs const auto& vs auto&&?

Comment thread clicache/src/CMakeLists.txt Outdated
string(REPLACE "/EHsc" "/EHa" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "/RTC1" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /clr /wd4947 /wd4251 /wd4635 /doc /we4488")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /clr /bigobj /wd4947 /wd4251 /wd4635 /doc /we4488")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm a little worried about remembering the context of these flags and why they're required.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, though if we remove it the project won't link, so context will be re-established. ;) Would you like a comment?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would find a comment to be helpful

*/
void setEndpoints(char* endpoints);
void setEndpoints(const std::string& endpoints);
void setEndpoints(std::string&& endpoints);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did you implement an rvalue ref version of this function? If so, why was it needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I was experimenting here. I should back it out. We can always add it later.

void setEndpoints(const std::string& endpoints);
Does not result in a copy to make the call but since internally we keep it a copy is made. No optimization can be made but none is really necessary unless the param is an r-value. The method also fails to communicate that we are keeping a copy.

void setEndpoints(std::string endpoints);
Communicates we are keeping a copy as copy is don't on the call. Unoptimized the copy happens also at the assignment to the member variable, though most modern compilers I believe will optimize that second copy out.

void setEndpoints(std::string&& endpoints);
Communicates a copy is kept and optimizes the r-value to avoid extra copies.

The two methods implemented are consistent with what the container class templates generate to handle l-values and r-values optimally.


/** Template CacheableKey class for primitive types. */
template <typename TObj, int8_t TYPEID, const char* TYPENAME,
const char* SPRINTFSYM, int32_t STRSIZE>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we want to change these template arguments from char* to std::string as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think we can, std::string is not constexpr. C++17 adds std::string_view which is constexpr.

@@ -219,8 +219,9 @@ void QueryHelper::populatePortfolioPdxData(std::shared_ptr<Region>& rptr,
auto keyport = CacheableKey::create(portname);

rptr->put(keyport, port);
LOGINFO("populatePortfolioPdxData:: Put for iteration current = %d done",
current);
// LOGINFO("populatePortfolioPdxData:: Put for iteration current = %d

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Intentional comment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it fills the logs. I should probably just delete but for diagnostics someone may want it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe LOGDEBUG is a good compromise?

bool pisLargeResultset = false) {
size_t querylen = static_cast<int>(strlen(pquery));
if (querylen < MAX_QRY_LENGTH) memcpy(_query, pquery, querylen);
memset(&_query[querylen], '\0', 1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yay! Glad to see these converted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes!

@@ -298,32 +305,6 @@ CacheableString::~CacheableString() {
}
}

int32_t CacheableString::logString(char* buffer, int32_t maxLength) const {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Woot!

if (bucketId == -1) {
return;
}
auto&& partition = fpResolver->getPartitionName(event);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same comment as above about intent of universal refs here.

return names[ordinal];
}

return names[NONE];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ugh.. I realize you didn't introduce this, but I'm not really a fan of using enum types as integers in c++.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree. Can you open a ticket and we can investigate alternatives?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if (INVALIDATE <= ordinal && ordinal <= LOCAL_DESTROY) {
return names[ordinal];
}
return nullptr;
return names[INVALID_ACTION];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same as other comment regarding enums

Comment thread cppcache/src/PoolFactory.cpp Outdated
}
}

cacheImpl->getPoolManager().addPool(name,
cacheImpl->getPoolManager().addPool(std::move(name),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why move?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why not? The method is PoolFactory::create(std::string name) so I am moving the already copied value into the member variable, rather than another copy. Saves the copy of the underlying char[].

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I feel like it makes it just a little easier to shoot ourselves in the foot (e.g. accidentally editing to use name after this line). Also since PoolFactory::create probably won't be called in a tight loop a copy doesn't seem too terrible?

@jake-at-work

Copy link
Copy Markdown
Contributor Author

@dgkimura Can I get a final blessing?

@jake-at-work jake-at-work merged commit b1d36ed into apache:develop Dec 2, 2017
mmartell pushed a commit to mmartell/geode-native that referenced this pull request Mar 6, 2018
- Reduces integration test runtimes by not starting http service in locators.
- Fixes some const method declarations.
mmartell pushed a commit to mmartell/geode-native that referenced this pull request Mar 6, 2018
- Reduces integration test runtimes by not starting http service in locators.
- Fixes some const method declarations.
jake-at-work added a commit to jake-at-work/geode-native that referenced this pull request Oct 6, 2018
- Reduces integration test runtimes by not starting http service in locators.
- Fixes some const method declarations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants