std::string: Short String Optimisation Buffer

Question 34 / 51 Correct so far: 0 (0 answered)

Snippet A

Sso

std::string processShort(const char* src) {
    std::string s = src;
    s += '!';
    return s;
}

std::string result = processShort(SHORT_STR);
Snippet B

Heap

std::string processLong(const char* src) {
    std::string s = src;
    s += '!';
    return s;
}

std::string result = processLong(LONG_STR);
Shared test data (shared-setup)
static const char SHORT_STR[] = "Hello, World!!";
static const char LONG_STR[]  = "Hello, World! This is longer.!";

Which snippet is faster?

Select the correct answer(s)