Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

Commit

Permalink
optimize StringFunctions::Repeat
Browse files Browse the repository at this point in the history
  • Loading branch information
AbnerZheng authored and apavlo committed Dec 28, 2017
1 parent 6b4135b commit 1a76ac5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/function/string_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,15 @@ type::Value StringFunctions::Repeat(const std::vector<type::Value> &args) {
std::string str = args[0].ToString();
int32_t num = args[1].GetAs<int32_t>();
std::string ret = "";
while (num--) {
ret = ret + str;

while (num > 0) {
if (num % 2) {
ret += str;
}
if (num > 1) {
str += str;
}
num >>= 1;
}
return (type::ValueFactory::GetVarcharValue(ret));
}
Expand Down

0 comments on commit 1a76ac5

Please sign in to comment.