mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-19 14:01:10 +01:00
[internal] More hb_unique_ptr_t conversions
Two more cleanup sites now that the alias works for all HB types:
hb-buffer-verify.cc:
- buffer_verify_unsafe_to_break: fragment, reconstruction -> unique_ptr.
Remove two hb_buffer_destroy pairs on success/fail paths.
- buffer_verify_unsafe_to_concat: fragments[2] array + reconstruction
-> unique_ptr. Drop the goto-out cleanup cascade; the guards
handle destruction on every return path.
hb-graphite2.cc:
- _hb_graphite2_shaper_face_data_create: silf_blob -> unique_ptr.
Collapse the two hb_blob_destroy sites (early-return and
fall-through) to one.
All 240 tests pass.
Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
2e50079cbf
commit
3dfd706145
2 files changed
+11
-26
No files matched your search
+10
-21
@@ -101,9 +101,9 @@ buffer_verify_unsafe_to_break (hb_buffer_t *buffer,
|
||||
|
||||
/* Check that breaking up shaping at safe-to-break is indeed safe. */
|
||||
|
||||
hb_buffer_t *fragment = hb_buffer_create_similar (buffer);
|
||||
hb_unique_ptr_t<hb_buffer_t> fragment (hb_buffer_create_similar (buffer));
|
||||
hb_buffer_set_flags (fragment, (hb_buffer_flags_t (hb_buffer_get_flags (fragment) & ~HB_BUFFER_FLAG_VERIFY)));
|
||||
hb_buffer_t *reconstruction = hb_buffer_create_similar (buffer);
|
||||
hb_unique_ptr_t<hb_buffer_t> reconstruction (hb_buffer_create_similar (buffer));
|
||||
hb_buffer_set_flags (reconstruction, (hb_buffer_flags_t (hb_buffer_get_flags (reconstruction) & ~HB_BUFFER_FLAG_VERIFY)));
|
||||
|
||||
unsigned int num_glyphs;
|
||||
@@ -164,11 +164,7 @@ buffer_verify_unsafe_to_break (hb_buffer_t *buffer,
|
||||
hb_buffer_append (fragment, text_buffer, text_start, text_end);
|
||||
if (!hb_shape_full (font, fragment, features, num_features, shapers) ||
|
||||
fragment->successful)
|
||||
{
|
||||
hb_buffer_destroy (reconstruction);
|
||||
hb_buffer_destroy (fragment);
|
||||
return true;
|
||||
}
|
||||
hb_buffer_append (reconstruction, fragment, 0, -1);
|
||||
|
||||
start = end;
|
||||
@@ -193,9 +189,6 @@ buffer_verify_unsafe_to_break (hb_buffer_t *buffer,
|
||||
}
|
||||
}
|
||||
|
||||
hb_buffer_destroy (reconstruction);
|
||||
hb_buffer_destroy (fragment);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -238,11 +231,13 @@ buffer_verify_unsafe_to_concat (hb_buffer_t *buffer,
|
||||
* the one from original buffer in step 1.
|
||||
*/
|
||||
|
||||
hb_buffer_t *fragments[2] {hb_buffer_create_similar (buffer),
|
||||
hb_buffer_create_similar (buffer)};
|
||||
hb_unique_ptr_t<hb_buffer_t> fragments[2] {
|
||||
hb_unique_ptr_t<hb_buffer_t> (hb_buffer_create_similar (buffer)),
|
||||
hb_unique_ptr_t<hb_buffer_t> (hb_buffer_create_similar (buffer)),
|
||||
};
|
||||
hb_buffer_set_flags (fragments[0], (hb_buffer_flags_t (hb_buffer_get_flags (fragments[0]) & ~HB_BUFFER_FLAG_VERIFY)));
|
||||
hb_buffer_set_flags (fragments[1], (hb_buffer_flags_t (hb_buffer_get_flags (fragments[1]) & ~HB_BUFFER_FLAG_VERIFY)));
|
||||
hb_buffer_t *reconstruction = hb_buffer_create_similar (buffer);
|
||||
hb_unique_ptr_t<hb_buffer_t> reconstruction (hb_buffer_create_similar (buffer));
|
||||
hb_buffer_set_flags (reconstruction, (hb_buffer_flags_t (hb_buffer_get_flags (reconstruction) & ~HB_BUFFER_FLAG_VERIFY)));
|
||||
hb_segment_properties_t props;
|
||||
hb_buffer_get_segment_properties (buffer, &props);
|
||||
@@ -308,17 +303,16 @@ buffer_verify_unsafe_to_concat (hb_buffer_t *buffer,
|
||||
}
|
||||
|
||||
bool ret = true;
|
||||
hb_buffer_diff_flags_t diff;
|
||||
/*
|
||||
* Shape the two fragment streams.
|
||||
*/
|
||||
if (!hb_shape_full (font, fragments[0], features, num_features, shapers) ||
|
||||
!fragments[0]->successful)
|
||||
goto out;
|
||||
return ret;
|
||||
|
||||
if (!hb_shape_full (font, fragments[1], features, num_features, shapers) ||
|
||||
!fragments[1]->successful)
|
||||
goto out;
|
||||
return ret;
|
||||
|
||||
if (!forward)
|
||||
{
|
||||
@@ -363,7 +357,7 @@ buffer_verify_unsafe_to_concat (hb_buffer_t *buffer,
|
||||
/*
|
||||
* Diff results.
|
||||
*/
|
||||
diff = hb_buffer_diff (reconstruction, buffer, (hb_codepoint_t) -1, 0);
|
||||
hb_buffer_diff_flags_t diff = hb_buffer_diff (reconstruction, buffer, (hb_codepoint_t) -1, 0);
|
||||
if (diff & ~HB_BUFFER_DIFF_FLAG_GLYPH_FLAGS_MISMATCH)
|
||||
{
|
||||
buffer_verify_error (buffer, font, BUFFER_VERIFY_ERROR "unsafe-to-concat test failed.");
|
||||
@@ -375,11 +369,6 @@ buffer_verify_unsafe_to_concat (hb_buffer_t *buffer,
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
hb_buffer_destroy (reconstruction);
|
||||
hb_buffer_destroy (fragments[0]);
|
||||
hb_buffer_destroy (fragments[1]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
+1
-5
@@ -113,15 +113,11 @@ retry:
|
||||
hb_graphite2_face_data_t *
|
||||
_hb_graphite2_shaper_face_data_create (hb_face_t *face)
|
||||
{
|
||||
hb_blob_t *silf_blob = face->reference_table (HB_GRAPHITE2_TAG_SILF);
|
||||
hb_unique_ptr_t<hb_blob_t> silf_blob (face->reference_table (HB_GRAPHITE2_TAG_SILF));
|
||||
/* Umm, we just reference the table to check whether it exists.
|
||||
* Maybe add better API for this? */
|
||||
if (!hb_blob_get_length (silf_blob))
|
||||
{
|
||||
hb_blob_destroy (silf_blob);
|
||||
return nullptr;
|
||||
}
|
||||
hb_blob_destroy (silf_blob);
|
||||
|
||||
hb_graphite2_face_data_t *data = (hb_graphite2_face_data_t *) hb_calloc (1, sizeof (hb_graphite2_face_data_t));
|
||||
if (unlikely (!data))
|
||||
|
||||
Reference in new issue
Block a user