in reply to Re^3: patchable settings
in thread patchable settings

How does this look (patch is on top of [id://patchable settings;displaycode|previous patch]):
--- Everything.pm 2004-10-05 11:28:38.716515200 -0700 +++ Everything.pm.new 2004-10-05 11:31:58.093204800 -0700 @@ -261,13 +261,28 @@ sub unescape sub unpackVars { my ($vars) = @_; + my $format_version = "00"; + + # version 00: original format + # version 01: keys are escaped, not just values + $format_version = $1 if $vars =~ s/^==(\d\d)&//; return {} unless $vars; - my %vars = map { split /=/ } split (/&/, $vars); - foreach (keys %vars) { - unescape $vars{$_}; - if ($vars{$_} eq ' ') { $vars{$_} = ""; } + my %vars; + + for (split /&/, $vars) { + my ($k,$v) = split /=/; + + if ($format_version > 0) { + unescape( $k, $v ); + } else { + unescape( $v ); + } + + $v = '' if $v eq ' '; + + $vars{$k} = $v; } return \%vars; @@ -296,7 +311,9 @@ sub packVars $$varsref{$_} = " " unless $$varsref{$_}; } - return join("&", map( $_."=".escape($$varsref{$_}), keys %$varsre +f) ); + # current format version: 01 + return join("&", "==01", + map( escape($_)."=".escape($$varsref{$_}), keys %$varsref) ); } ##################################################################### +########
I think I've placed more emphasis (or at least tried to) on readability and reuse than what you had suggested. I'm guessing it will be about as fast as the existing code. If you are ok with this, I'll try it out on the test server.

Replies are listed 'Best First'.
Re^5: patchable settings
by demerphq (Chancellor) on Oct 06, 2004 at 09:20 UTC

    I think I've placed more emphasis (or at least tried to) on readability and reuse than what you had suggested.

    Yeah style wise I agree. But there was a point to my use of that type of packing scheme. Its a lot faster and the resulting text is smaller than the current one and it renders the text less illegibile in raw form. Just avoiding the overhead of the escape call is worthy IMO. Also the scheme I used can be made a litte more dynamic and self documenting by a more verbose rewrite. I think its worth finding out the full requirements of this (ie possible charset restrictions) and getting a fast light implementation done once and for all. Settings are used a _lot_, shaving time on them is very worthwhile IMO.

    But i definately like this a lot more than the earlier ideas. One last thing, can I suggest that you use == at the start of the string? What you have there is a possible valid start of a vars. '=00&' could come from { ''=>'00','1'=>'1' } for instance. I suggest '==00&' so that its impossible to occur under the current codebase.


    ---
    demerphq

      First they ignore you, then they laugh at you, then they fight you, then you win.
      -- Gandhi

      Flux8


      Changed to use ==.

      Even the 100+ sub calls it is doing per page is not going to take that long, but I'll take a stab at improving it later today or Sunday.