Commit d24a78d1 authored by Tor Didriksen's avatar Tor Didriksen

Backport of Bug#14171740 65562: STRING::SHRINK SHOULD BE A NO-OP WHEN ALLOCED=0

parent aef1982b
/*
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -195,8 +195,12 @@ class String
}
bool real_alloc(uint32 arg_length); // Empties old string
bool realloc(uint32 arg_length);
inline void shrink(uint32 arg_length) // Shrink buffer
// Shrink the buffer, but only if it is allocated on the heap.
inline void shrink(uint32 arg_length)
{
if (!is_alloced())
return;
if (arg_length < Alloced_length)
{
char *new_ptr;
......@@ -212,7 +216,7 @@ class String
}
}
}
bool is_alloced() { return alloced; }
bool is_alloced() const { return alloced; }
inline String& operator = (const String &s)
{
if (&s != this)
......
/*
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -225,8 +225,12 @@ class String
}
bool real_alloc(uint32 arg_length); // Empties old string
bool realloc(uint32 arg_length);
inline void shrink(uint32 arg_length) // Shrink buffer
// Shrink the buffer, but only if it is allocated on the heap.
inline void shrink(uint32 arg_length)
{
if (!is_alloced())
return;
if (arg_length < Alloced_length)
{
char *new_ptr;
......@@ -242,7 +246,7 @@ class String
}
}
}
bool is_alloced() { return alloced; }
bool is_alloced() const { return alloced; }
inline String& operator = (const String &s)
{
if (&s != this)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment