diff --git a/mindspore/ccsrc/utils/system/sha256.h b/mindspore/ccsrc/utils/system/sha256.h index 0ddc714260..cb44f0bfa4 100644 --- a/mindspore/ccsrc/utils/system/sha256.h +++ b/mindspore/ccsrc/utils/system/sha256.h @@ -100,28 +100,27 @@ bool ProcessInner(const std::string &message, const int &bias, uint32_t *digest, w[i] = sigma3(w[i - 2]) + w[i - 7] + sigma2(w[i - 15]) + w[i - 16]; } - std::shared_ptr hash(new uint32_t[digest_size], std::default_delete()); + std::shared_ptr hash(new uint32_t[digest_size]()); size_t mem_size = digest_size * sizeof(uint32_t); auto ret = memcpy_s(hash.get(), mem_size, digest, mem_size); if (ret != EOK) { return false; } for (int i = 0; i < kIterationNumber; ++i) { - uint32_t t1 = - w[i] + constant[i] + hash.get()[7] + sigma1(hash.get()[4]) + ch(hash.get()[4], hash.get()[5], hash.get()[6]); - uint32_t t2 = sigma0(hash.get()[0]) + ma(hash.get()[0], hash.get()[1], hash.get()[2]); + uint32_t t1 = w[i] + constant[i] + hash[7] + sigma1(hash[4]) + ch(hash[4], hash[5], hash[6]); + uint32_t t2 = sigma0(hash[0]) + ma(hash[0], hash[1], hash[2]); for (int j = digest_size - 1; j >= 0; --j) { if (j == 4) { - hash.get()[j] = hash.get()[j - 1] + t1; + hash[j] = hash[j - 1] + t1; } else if (j == 0) { - hash.get()[j] = t1 + t2; + hash[j] = t1 + t2; } else { - hash.get()[j] = hash.get()[j - 1]; + hash[j] = hash[j - 1]; } } } for (int i = 0; i < digest_size; ++i) { - digest[i] += hash.get()[i]; + digest[i] += hash[i]; } return true; } diff --git a/mindspore/core/ir/tensor.cc b/mindspore/core/ir/tensor.cc index decd09d522..c69d6ffdda 100644 --- a/mindspore/core/ir/tensor.cc +++ b/mindspore/core/ir/tensor.cc @@ -28,7 +28,6 @@ #include #include #include -#include #include "abstract/abstract_value.h" @@ -373,25 +372,17 @@ class TensorDataImpl : public TensorData { std::is_same::value) { return str; } - // Use regular expressions to replace placeholders. - std::regex pattern("#+"); - std::smatch result; - int bias = 0; - std::string::const_iterator start = str.begin(); - std::string::const_iterator end = str.end(); - while (std::regex_search(start, end, result, pattern)) { - const int len = result.str(0).length(); - const int pos = result.position(); - bias += pos; - if (bias > static_cast(str.length())) { - return ""; + // Replace # with placeholder. + size_t index = str.find('#'); + while (index != str.npos) { + size_t pos = index; + while (str[pos] == '#') { + pos++; } - // Replace # with placeholder. + int len = pos - index; std::string space(max_width - len, ' '); - str = str.replace(bias, len, space); - // Update the starting position of the search. - start = str.begin() + bias; - end = str.end(); + str = str.replace(index, len, space); + index = str.find('#', index); } return str; }