[ic] [interchange] Only apply GDBM filters if they are not already installed
Stefan Hornburg (Racke)
racke at linuxia.de
Fri Aug 31 10:33:04 UTC 2012
On 08/31/2012 04:04 AM, Mike Heins wrote:
> Quoting David Christensen (interchange-cvs at icdevgroup.org):
>> commit 0c31ea3287df97c8fedbf23ad71244e4ebe019c7
>> Author: David Christensen<david at endpoint.com>
>> Date: Thu Aug 30 20:01:28 2012 -0500
>>
>> Only apply GDBM filters if they are not already installed
>>
>> In certain circumstances, using the same GDBM-based file in multiple catalogs with
>> GDBM_ENABLE_UTF8=1 set was causing the GDBM filters to be installed multiple times on the same
>> handle, which was resulting in encoding/decoding errors.
>>
>> Vend::Table::GDBM will now only install the filters if they do not exist on this handle, which
>> should preserve existing behavior plus account for these corner-cases.
>>
>> lib/Vend/Table/GDBM.pm | 8 ++++----
>> 1 files changed, 4 insertions(+), 4 deletions(-)
>> ---
>> diff --git a/lib/Vend/Table/GDBM.pm b/lib/Vend/Table/GDBM.pm
>> index fb82dbb..559f904 100644
>> --- a/lib/Vend/Table/GDBM.pm
>> +++ b/lib/Vend/Table/GDBM.pm
>> @@ -150,10 +150,10 @@ sub apply_utf8_filters {
>> my $out_filter = sub { $_ = encode('utf-8', $_) };
>> my $in_filter = sub { $_ = decode('utf-8', $_) };
>>
>> - $handle->filter_store_key($out_filter);
>> - $handle->filter_store_value($out_filter);
>> - $handle->filter_fetch_key($in_filter);
>> - $handle->filter_fetch_value($in_filter);
>> + $handle->filter_store_key($out_filter) unless $handle->filter_store_key();
>> + $handle->filter_store_value($out_filter) unless $handle->filter_store_value();
>> + $handle->filter_fetch_key($in_filter) unless $handle->filter_fetch_key();
>> + $handle->filter_fetch_value($in_filter) unless $handle->filter_fetch_value();
>>
>
> Couldn't we cut down object calls? It seems to me that you should be able
> to do:
>
> --- a/lib/Vend/Table/GDBM.pm 2012-08-30 22:02:19.152103476 -0400
> +++ a/lib/Vend/Table/GDBM.pm 2012-08-30 22:01:16.000000000 -0400
> @@ -146,6 +146,8 @@
> sub apply_utf8_filters {
> my ($handle) = shift;
>
> + return if $handle->filter_store_key();
> +
> #::logDebug("applying UTF-8 filters to GDBM handle");
>
> my $out_filter = sub { $_ = encode('utf-8', $_) };
>
> Every little bit helps. That reduces object calls by three and subroutine
> creation overhead by two.
>
What about using DBM_Filter?
https://metacpan.org/module/DBM_Filter
That seems to have an easier interface and comes with Perl.
Regards
Racke
--
LinuXia Systems => http://www.linuxia.de/
Expert Interchange Consulting and System Administration
ICDEVGROUP => http://www.icdevgroup.org/
Interchange Development Team
More information about the interchange-users
mailing list